开发者

Wordpress auth library for Codeigniter (or other framework)

开发者 https://www.devze.com 2023-03-30 12:35 出处:网络
I\'m looking to buil开发者_Python百科d a library for Codeigniter that communicates with the Wordpress database to provide functions such as login, logout and register. Logging in through the Codeignit

I'm looking to buil开发者_Python百科d a library for Codeigniter that communicates with the Wordpress database to provide functions such as login, logout and register. Logging in through the Codeigniter app should not make a difference compared to logging in through the Wordpress site. So I can switch between the two of them without having to login twice.

I'm not looking to "integrate Wordpress with Codeigniter" and whatever else people are asking about. I just want to use the Wordpress DB to authenticate users and then create the right cookies etc.

If anybody knows of any projects already existing that would be helpful to me as I embark on this I would like to hear about them.


This is an example of the integration that seems to need. It is not CI, but it is only a couple of functions and can serve as a starting point.


EDITED

Revisiting the issue, it seems to me that you ask as it is cumbersome because you have to rewrite things that WP does very well.

Either way, the names of the cookies consist of a prefix and a compile id of the site, it's just a md5 of the URL of the blog. Are defined in the file "wp-includes/default-constants.php".

The one you're interested in could be used like this:

//$wp_url like this: http://domain.com, Exactly as written in the configuration
$cookie= "wordpress_logged_in_".md5($wp_url);

The contents of this cookie will be something like: admin|7C1314493656|7Cdd41a2cd52acbaaf68868c850f094f9f

$cookie_content= explode("|",$this->input->cookie($cookie,true));
if(count($cookie_content)>0){
    $user_name= $cookie_content[0];
}else{
    //No user identified, do something...
}

Bonus Pack

While studying the WP code was writing a small library that does just that, using the WP login and access levels directly in CI. Available in bitbucket GPL2 licensed (as WP): CiWp-Auth.


WordPress uses MD5 to encrypt their password so you can just query the wp_users table with the username and the password after you MD5 it. The query would look something like this:

$credentials = array(
    'user_login' => $this->input->post('username'),
    'user_pass' => md5($this->input->post('password'))
);
$this->db->where($credentials);
$user = $this->db->get('wp_users');

That should return the user account info you are looking for in the $user var, then you can work with it just like any other authentication method.

0

精彩评论

暂无评论...
验证码 换一张
取 消