WordPress.org

Ready to get started?Download WordPress

Forums

Create WordPress Sessions from CakePHP (2 posts)

  1. neohunter
    Member
    Posted 5 years ago #

    Hello, im developing a webapp using cakephp and i want to merge it with WordPress to use it as a CMS. I need help in order to create the session from my cakephp on wordpress. (i dont want the users to log in two times.)

    http://www.myapp.com <--- app
    http://www.myapp.com/blog <--- wordpress installation

  2. JeremyVisser
    Member
    Posted 5 years ago #

    I am a complete CakePHP n00b, but I'll try and reply to you as best I can.

    First, what you need is shared authentication. You either need to modify WordPress to get its username and password data from CakePHP's tables, or modify your Cake app to gets its username/password data from WordPress.

    Both should be doable. I know WordPress has a file called wp-includes/pluggable.php. All the functions in there can be replaced by a plugin. Some of the functions in pluggable.php are related to logging in, so you could possibly hack WordPress to fetch its user data from your Cake tables that way.

    Once you have the user tables shared, you still have the issue of needing to log in twice. Making the user logged in to WordPress should be as simple as setting the right cookies with the right password hashes inside them.

    After logging into my WordPress site, I have four cookies:

    • wordpress_
    • wordpress_
    • wordpress_logged_in_
    • wordpress_test_cookie

    I am not sure why they have underscores after them -- perhaps it is because I am running WordPress MU.

    Anyway, the content of the first three cookies looks something like this:

    yourusername%somerandomdata

    So, basically, it has the username, and what is most likely a salted hash of the password.

    I don't know how to calculate that hash, but once you manage to do it, setting the cookie from within your CakePHP application should be as simple as calling the setcookie function.

    I'm not sure if CakePHP has a "proper" way of setting cookies, and even if it does, it would probably not allow you to set the cookies with the right names to suit WordPress.

    Once the cookies are set, you should be correctly logged in to WordPress.

    If anybody here knows any better how WordPress' login cookies are set, your feedback is most welcome.

    Neohunter, I hope I have been a help, and if not, please let me know why. :)

Topic Closed

This topic has been closed to new replies.

About this Topic