3

I am trying to integrate my site to use the bbpress/wordpress user system.

All I need is the ability to get the User Name and/or User ID of the person currently on my site. I don't really need any other functionality from bbpress or wordpress on the site.

If I could get the user's ID and then the ability to get the user's name from that ID would be perfect for all of my needs.

Additional Info: My site is ran on PHP5 and MySQL, I have wordpress and bbpress upto date and currently integrated with each other.

Jayrox
  • 4,335
  • 4
  • 40
  • 43

1 Answers1

3

Have you tried just printing out the contents of $_COOKIE? Mine contains the following:

Array
(
    [wordpress_test_cookie] => WP Cookie check
    [wordpress_logged_in_##########] => ceejayoz|#####|##########]
)

Should be simple for you to parse.

foreach($_COOKIE as $key => $value) {
  if(preg_match('@^wordpress_logged_in_@', $key) {
    $cookie = explode('|', $_COOKIE[$key]);
    $username = $cookie[0];
  }
}
ceejayoz
  • 176,543
  • 40
  • 303
  • 368
  • mine has ['wordpress_##############################'] => "admin|##########|###############################" – Jayrox Feb 28 '09 at 03:01
  • where does the first variable after wordpress_ come from? – Jayrox Feb 28 '09 at 03:01
  • Not sure, I'd say create a new user and see if it's different. It may be a per-install hash. If not, step through $_COOKIE with a foreach() loop and look for wordpress_logged_in_*. – ceejayoz Feb 28 '09 at 03:11
  • Thanks, I'll write up a quick function to sanitize the $username from the $cookie[0], then an SQL statement to get the $user_id from the wp_users table. – Jayrox Feb 28 '09 at 03:19
  • I was reading all over the web about how the username was double hashed in the cookie. i should have just dumped it in the first place and saw what i had to play with. – Jayrox Feb 28 '09 at 03:21