WJN WJN - 1 year ago 59
PHP Question

How to determine from outside of wordpress if a visitor is logged into Wordpress

Using php is it possible to determine if a visitor to my site is logged into the wordpress area of my site.

By this I mean the wordpress area of my site (which has registration) is in for example


I would like to know from
if they are logged into the wordpress area

Answer Source

OK what seems to get overlooked is that when trying to access wordpress from a different folder to where wordpress is installed then using the following code does not work... is_user_logged_in() will always return false.

define( 'WP_USE_THEMES', false ); 
Include_once($_SERVER['DOCUMENT_ROOT'] . '/members/wp-load.php');
if ( is_user_logged_in() ) {echo ' You are currently logged in.'. '<br />';}
{    echo ' You are currently not logged in.'. '<br />';}

I managed to find a workaround that for me at least works. I was building an html page that needed to test if the user was logged into the wordpress area on my site. So what I did was place the above test into a file that WAS in the wordpress folder. Then simply used an IFrame in my html that used as it's src= the file that was in the wordpress folder. That then echoes out what was need depending upon the user being logged in or logged out.

Probably a sloppy solution but at least it works.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download