• I have a program running independent of wordpress, but I am setting it up to use the same user data. I’d like to use the wordpress admin for logging in and updating, but the URL’s from my software aren’t compatible with the wordpress permalinks so I’d like to keep it separate. I’d would like to check and see if a user is logged in and get their user_ID but I can’t seem to find how that’s stored in the wordpress cookie. The codex seems to only apply to versions <2.5, can anybody provide some insight in how to check if a user is logged in and fetch their user_ID outside of wordpress?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter laqrhead

    (@laqrhead)

    Ok, so I think I’ve found the cookie name:

    wordpress_logged_in_HASH

    where HASH is there seems to be a site specific hash. Anybody know what it is, or how I can get it outside wordpress? For the one site I can just copy it, but it won’t work on other sites.

    The values go like this I think:

    username|someNumber?|hashedPassword?

    What is the middle value for?

    Anyways, I think I might be able to get by on this, but if anyone can provide more clues, I’d appreciate it.

    Thread Starter laqrhead

    (@laqrhead)

    Ok, so I can get it from here.

    You can set the cookie name in the wp-config.php file by adding:

    define('LOGGED_IN_COOKIE', 'my_cookie_name');

    The default is defined in wp-settings.php on line 392 as:

    define('LOGGED_IN_COOKIE', 'wordpress_logged_in_' . COOKIEHASH);

    So now I’ll always know what the cookie name is, so I can extract the username from the cookie value. Something like this should do the trick assuming that you have established your DB connection.

    $userArr=explode('|',$_COOKIE[my_cookie_name]);
    $user_login=$userArr[0];
    
    $sql="SELECT ID FROM wp_users WHERE user_login LIKE '$user_login'";
    $query=mysql_query($sql);
    $resultArray=mysql_fetch_array($query);
    $user_id=$resultArray[ID];

    If you have a better way, let me know.

    laqrhead,

    Did you ever get this to work!

    I am trying to do the same thing!

    I have been successful acquiring the $user_id through wp globals but it only works with IE not Sarfari or Firefox.

    So I then tried using the cookies but I have gotten the same results.

    If you got this to work correctly in all browsers I would sure love some help!

    Thanks!
    Voogah

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Cookie Login data’ is closed to new replies.