【问题标题】:Access Wordpress session from cake PHP site从 cake PHP 站点访问 Wordpress 会话
【发布时间】:2011-11-10 14:03:10
【问题描述】:

这对我来说是相当困难的。请帮忙。 我在根域(比如 mysite.com)中使用 cake PHP 创建了一个网站,在名为“blog”的目录中创建了一个博客(mysite.com/blog)。 我在 PHP 站点中有一个注册/登录功能。 所以我在这里想要的是,每当会员使用登录表单登录主站点时,每当他打开博客(mysite.com/blog)时,他都应该与登录主 PHP 站点的同一用户一样登录。 同理,每当新用户在 PHP 主站点使用注册表单进行注册时,他都应该成为 wordpress 博客的用户。

谢谢。

【问题讨论】:

    标签: php forms wordpress cakephp login


    【解决方案1】:

    在您的主站点中,您必须使用 wp_signon 包含 WP 的功能

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

    然后,您可以使用

    在 WP 中自动登录用户
    $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();
    }
    

    这应该可以正常工作,希望对您有所帮助。

    【讨论】:

    • 非常感谢奥古斯丁。我将这些放在我的主站点的 index.php 中,如下所示(包括上述两行之后):$credentials = array(); $credentials['user_login'] = $_SESSION['user']; // john $credentials['user_password'] = $_SESSION['pwd']; // 1234 $credentials['remember'] = true; $user = wp_signon( $creds, false ); if ( is_wp_error($user) ) { //login failed echo $user->get_error_message(); } 但它不适用于 wordpress,即使有一个名为 john 的用户,密码为 1234 我怎么了?
    【解决方案2】:

    要让用户自动登录 wordpress,请查看:

    http://codex.wordpress.org/Function_Reference/wp_signon

    要创建用户看看:

    http://codex.wordpress.org/Function_Reference/wp_create_user

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-09
      • 1970-01-01
      • 1970-01-01
      • 2015-12-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多