• Hello Friends,

    I am making big site with uses WP, phpBB and other ready opensource software.

    My requirement is I wanted to check if user in WP is logged in and what is his ID. but I wanted to check it in other external files.
    Ex. I wanted to check in phpBB OR coustom php code in other folder.

    my folder is like
    mydomain.com/wp [Where is where wordpress is stored.]
    mydomain.com/wp/forum [where my php BB is stored.]
    I need to put some code at mydomain.com/wp/forum/somefile.php while let me know Wp logged in user info.

    how this is possible.
    kindly advise.

    Thanks
    Jayesh

Viewing 5 replies - 1 through 5 (of 5 total)
  • you’d need to require wp-load
    require_once('wp-load.php');
    only you’d change the path to match your relative path from where you are. so in somefile.php it would read:
    require_once('../wp-load.php');
    which tells it to go back one directory then look for the file.

    with it loaded, here is how i get the ID for my plugin:

    global $current_user;
    	get_currentuserinfo();
    	$ID = $current_user->ID;

    but i have also gotten it this way:
    $user_id = get_current_user_id();

    idk if it matters, or how.

    note: mine have no check for if they are logged in, as in order for my script to run they must be. but here is the codex entry for the wp function “is_user_logged_in
    -Kyle

    Thread Starter Jayesh Patel

    (@thewowimages)

    Hi Kyle,

    thanks for your reply.
    I used same code as you have suggested.

    But it returns me 0 as id ??
    while I try to use other blog information via bloginfo function I am getting all correct values.

    I checked cookies and I found that word press related session cookies are get deleted on other page.
    I mean on mydomain.com/wp/forum/somefile.php I am able to get all otehr blog info but not WP session ??

    Kindly advise if you have any more suggestions.

    Thanks
    Jayesh

    0 should only be shown if the user is not logged in, i am assuming you DID log in before trying so the only explanation would be the cookies as you mentioned.

    idk why they’re being deleted. you checked remember when you logged in? that is where i would bet the problem lies (as long as you ARE logged in)

    Thread Starter Jayesh Patel

    (@thewowimages)

    Hi Kyle,

    Yes user is already logged in.
    PLUS when I move to WP to Forum it gives me 0 as user id and one I comes back form forum to WP it again shows me user id.

    Do you think is there any thing related to cookies path?

    Thanks
    Jayesh

    Hi Jayesh,
    did you find a solution?

    WP and Forum have the same db? The IDs are the same for Forum and WP?

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Need to check WP logged in user ID in other application’ is closed to new replies.