{"id":995679,"date":"2009-02-21T21:14:43","date_gmt":"2009-02-21T21:14:43","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/authenticate-wordpress-login-from-external-php-script\/"},"modified":"2016-08-19T03:34:15","modified_gmt":"2016-08-19T03:34:15","slug":"authenticate-wordpress-login-from-external-php-script","status":"closed","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/authenticate-wordpress-login-from-external-php-script\/","title":{"rendered":"Authenticate WordPress login from External PHP script?"},"content":{"rendered":"<p>Hi,<\/p>\n<p>I&#8217;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&#8217;t care which role they have).<\/p>\n<p>I don&#8217;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 &#8211; 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??<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\nini_set(&#8216;display_errors&#8217;, 1);<br \/>\nrequire_once(&#8216;..\/..\/..\/wp-config.php&#8217;); \/\/Please make sure that the path is correct<\/p>\n<p>global $user_ID;<\/p>\n<p>$wp_user = new WP_User($user_ID);<br \/>\nif (true == empty($wp_user) || $wp_user-&gt;ID &lt; 1) {<br \/>\n\/\/In this case we are dealing with a visitor, not member<br \/>\nwp_die(&#8220;Would you please be so kind to log in?&#8221;);<br \/>\n}<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<\/p>\n<p>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.<\/p>\n<p>Any help greatly appreciated, I don&#8217;t know why this is so difficult, seems it would be a fairly straight-forward way to do it?<\/p>\n<p>Thanks,<br \/>\n-Brett<\/p>\n","protected":false},"template":"","class_list":["post-995679","topic","type-topic","status-closed","hentry","topic-tag-authentication","topic-tag-external","topic-tag-php","topic-tag-script"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/995679","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/995679\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=995679"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}