从蛋糕PHP站点访问Wordpress会话 [英] Access Wordpress session from cake PHP site

查看:138
本文介绍了从蛋糕PHP站点访问Wordpress会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这对我来说很困难。请帮忙。
我有一个网站创建的PHP根域中的PHP(说mysite.com)和一个博客在一个名为blog(mysite.com/blog)的目录。
我在PHP网站上有一个注册/登录功能。
所以我想要的是,每当一个成员在主站点登录使用登录表单,每当他打开博客(mysite.com/blog),他shoulb将登录为同一用户登录主PHP站点。
以同样的方式,每当一个新用户注册在主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.

感谢。

推荐答案

在您的主要网站中,您必须使用 wp_signon

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

然后,您可以使用

$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.

这篇关于从蛋糕PHP站点访问Wordpress会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆