douhui4831 2011-09-05 11:57
浏览 30
已采纳

从蛋糕PHP站点访问Wordpress会话

This is quite difficulty for me. Please help. I've a website created with cake PHP in root domain (say mysite.com) and a blog in a directory called "blog" (mysite.com/blog). I have a register/login feature in PHP site. So what I want here is, whenever a member login in the main site using the login form, whenever he open the blog (mysite.com/blog), he shoulb be as logged in as the same user logged in the main PHP site. In the same way, whenever a new user sign-up with the registration form in the main PHP site, he should become an user in the wordpress blog.

Thanks.

  • 写回答

2条回答 默认 最新

  • 普通网友 2011-09-05 14:58
    关注

    In your main site, you have to include WP's functions by using wp_signon

    define('WP_USE_THEMES', false); //this disables the theme
    require('/blog/wp-blog-header.php'); //includes wordpress functions
    

    And then, you can auto-login a user in WP by using

    $credentials = array();
    $credentials['user_login'] = 'example';
    $credentials['user_password'] = 'plaintextpw';
    $credentials['remember'] = true;
    $user = wp_signon( $creds, false );
    if ( is_wp_error($user) ) {
    //login failed
    echo $user->get_error_message();
    }
    

    This should work fine, I hope this helps you.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面