How to determine from a different folder (outside wordpress) if a visitor is logged into Wordpress

The WordPress area of my site (which has registration) is in for example mydomain.com/members/

I would like to know from a PHP routine in my public_html root mydomain.com/offers.php if they are logged into the WordPress area mydomain.com/members

I have tried various things to try and get this to work without success. get_current_user_id() always returns 0 or is_user_logged_in() returns false.

If it helps to give me the correct solution, my WordPress uses the theme MH-Magazine, and uses the plugins Paid Memberships Pro and Theme My Login.

Topic outside-wordpress php Wordpress

Category Web


<?php
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 />';}
else
{    echo ' You are currently not logged in.'. '<br />';}
?>

The above code returns You are currently not logged in. The above code when executed from the SAME folder that wordpress is in does work. My requirement is to execute code from a DIFFERENT folder to where wordpress resides.


To use all the WordPress functions in any non- WordPress pages, you can use

define( 'WP_USE_THEMES', false ); 
Include_once('wp-load.php');

Then, is_user_logged_in() will work, and user cookie, session and id could be retrieve.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.