Login via PHP File?
-
I’m using WordPress for my website and installed it into the root, I’m creating a game on Unity where I’d like to login to the website to check if the user exists and then print Success! so that Unity can confirm they exist.
I’ve tried to search for ways people have done this but it always results in them being shutdown or told to login through WP. But as you can see I need to be able to login from outside of WP.
Unity sends the Username and Password to the URL and inside the PHP I need to grab them with $_GET’s, the code I have so far works but because I’m importing the base template file I’m getting all of WP’s template too which I can’t have as I just need to receive that one line stating fail or success.
Code I have so far:
<?PHP require($_SERVER['DOCUMENT_ROOT']."/index.php"); // Include wordpress main index file,we get access to "all wp-function(not tested)" in our external file. define('WP_USE_THEMES', false); // Do not show themes header("HTTP/1.1 200 OK"); //Sometimes error occurs,so to fix we set headers $creds = array(); $creds['user_login'] = $_GET['username']; $creds['user_password'] = $_GET['password']; $creds['remember'] = true; $user = wp_signon( $creds, false ); // Sigining in a WP User if( is_wp_error($user)) { print 'oops!! we got some error in sigining in '.$user->get_error_message(); } else { print 'Success'; } ob_end_flush(); ?>
- The topic ‘Login via PHP File?’ is closed to new replies.