Authenticate WordPress login from External PHP script?
-
Hi,
I’m not sure WHY I cannot find this information. Basically I need to run several external PHP scripts on the same domain as my WordPress blog. What I want to do is authenticate that the person running the external PHP script is currently logged in to WordPress (at any level, I don’t care which role they have).
I don’t need anything fancy, or even very secure, because I know my users are not tech savvy enough to hack through it. All I need is something simple that will look to see – is this person currently logged in to my WordPress blog right now. Here is what I had, it did work for a few days, now it does not work??
——————–
ini_set(‘display_errors’, 1);
require_once(‘../../../wp-config.php’); //Please make sure that the path is correctglobal $user_ID;
$wp_user = new WP_User($user_ID);
if (true == empty($wp_user) || $wp_user->ID < 1) {
//In this case we are dealing with a visitor, not member
wp_die(“Would you please be so kind to log in?”);
}
————————-Any ideas on why this used to work, and now it does not, or why it cannot work now? Any other ways I can do this? Every time I run it now I end up with $wp_user=NOT EMPTY, and ID=0, regardless of whether I am logged in to my WordPress blog, or not? The only thing different, I changed themes, I did try changing back to the new theme, it did not fix the problem, so that might not be what caused this.
Any help greatly appreciated, I don’t know why this is so difficult, seems it would be a fairly straight-forward way to do it?
Thanks,
-Brett
- The topic ‘Authenticate WordPress login from External PHP script?’ is closed to new replies.