• Paul Ille

    (@tunnleram)


    Hi,

    I’ve read some posts and did some fiddling but I can’t seem to get things going. I’m integrating WP into an existing webpage and from that page I’m trying to check on when a user is logged in.

    I’m using the following code.

    <?php global $user_ID; get_currentuserinfo();


    if ($user_ID)
    {
    echo "logged in";
    }
    else
    {
    echo "logged out";
    }
    ?>

    When I use this in sidebar.php to test it it works fine, but on my test page it does not.

    What am I missing? I have the


    <?php $blog = 1; require('wordpress/wp-blog-header.php'); ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="https://www.w3.org/1999/xhtml">

    at the top of the page.

Viewing 15 replies - 1 through 15 (of 24 total)
  • Thread Starter Paul Ille

    (@tunnleram)

    Any help is much appreciated.

    Thread Starter Paul Ille

    (@tunnleram)

    Ok, where is the get_currentuserinfo(); function defined? Do I have to include that page?

    Thread Starter Paul Ille

    (@tunnleram)

    Ok, well I tried to include that page, but it gave me an error. Something tells me having the wp-blog-header.php included is enough, but then why is it not able to get userdata??

    It works fine on the sidebar.php.

    It would really be appreciated if someone has any idea at all. I know the solution is probably simple, but I’m just unaware of it.

    Thread Starter Paul Ille

    (@tunnleram)

    Once again, the get_currentuserinfo is not pulling any info for me.


    <?php global $user_ID; get_currentuserinfo();

    if ($user_ID)
    {
    echo "logged in";
    }
    else
    {
    echo "logged out";
    }
    ?>

    Does this not work outside of WordPress?
    Do I need to include something that I’m not?

    Anyone?

    Thread Starter Paul Ille

    (@tunnleram)

    Not one person here has any idea about this?

    Kafkaesqui

    (@kafkaesqui)

    You’re duplicating what a number of WordPress internals accomplish, so I can’t say where it’s going south on you. Does this page appear on the exact same domain as your blog?

    One thing to try is to nix get_currentuserinfo() in your statement:

    <?php
    global $user_ID;
    if ($user_ID) {
    echo "logged in";
    } else {
    echo "logged out";
    }
    ?>

    If that fails, replace $user_ID in your test with $user_level or $user_login. Any of these should be available as global vars to a logged-in visitor of the blog.

    Thread Starter Paul Ille

    (@tunnleram)

    I put up a quick testing page with a few variables, but none of them seem to display info.

    Here are the tests I used:
    <?php global $user_ID; get_currentuserinfo();

    if ($user_ID)
    {
    echo "logged in";
    }
    else
    {
    echo "logged out";
    }
    ?>

    Should show username, userlevel and user id:
    <?php global $userdata;
    get_currentuserinfo();

    echo('Username: ' . $userdata->user_login . '\n');
    echo('User level: ' . $userdata->user_level . '\n');
    echo('User ID: ' . $userdata->ID . '\n');
    ?>

    Should show user nickname and their email address:
    <?php global $user_nickname, $user_email;
    get_currentuserinfo();

    echo($user_nickname . "'s email address is: " . $user_email);
    ?>

    That page is here – https://www.paulille.com/testing.php

    Here’s the wordpress – https://www.paulille.com/wordpress/ The very same code works fine in the sidebar.

    I also have the include line at the top of the pages
    <?php $blog = 1; require('wordpress/wp-blog-header.php'); ?>

    Any ideas?

    Thread Starter Paul Ille

    (@tunnleram)

    This issue is really annoying. There are so many things I can’t do unless I solve this.

    It must be something stupid, but I can’t figure it out.

    Thread Starter Paul Ille

    (@tunnleram)

    I tried to use the_excerpt_reloaded mod and when I do that doesn’t work on my index page either.

    Here’s the code on my index page https://www.paulille.com/files/index.txt
    (rightclick save target etc)

    Anyone see anything that could be stopping me from using some things on my site?

    I think using wp-blog-header.php may be a little overkill for what you want to do, as this file handles all of the wordpress internals (such as switching between pages/posts/categories etc) it also handles the permalink re-writes etc.

    Something as simple as this:

    <?php
    require_once(‘wp-config.php’);
    get_currentuserinfo();
    print “$user_login<br/>$user_ID<br/>$user_level<br/>”;
    ?>

    works fine for me (it’s in my wordpress directory as that is the root of the site), but i can’t see why it wouldn’t work in your situation.

    cheers.
    jared.

    Thread Starter Paul Ille

    (@tunnleram)

    Yeah thx man, but that doesn’t work either. I just don’t get it. What in the world would prevent this from working?

    It’s silly to me that it doesn’t work outside of the wordpress folder even with the proper includes.

    I’m just bumping this topic becuase I’m trying to do the very same thing… with the very same results. Any experts have input?

    I’m happy to have a closer look at your setups, but it may be easier if you contact me outside the forums.

    You can find my contact details on my website if you follow the link from my profile.

    I don’t know how, but between last night and today it’s sterted working. I have a test page created in the home directory (same as my wordpress install) and it displays the login name of the person logged in and nothing if the user is not logged in.

    Thread Starter Paul Ille

    (@tunnleram)

    Mine still doesn’t work, but I haven’t tried in a while. Seems rustin is working from inside the WordPress folder while mine is outside. I can get it to work inside of that folder just fine it seems.

    Gonna fire you off an email jaredquinn, appreciate the offer.

Viewing 15 replies - 1 through 15 (of 24 total)
  • The topic ‘Check for login outside WordPress’ is closed to new replies.