I have a PHP script located in my WordPress installation’s root folder
wordpress-root/includes/login.php
When I login from the home page, I call this script via AJAX to log in a user.
This is what the script does:
if (eveything checks out)
{
//set session variables to track user
//generate a unique auth token
//store auth token in db
//set cookies
setcookie('email',$email,mktime(0,0,0,12,31,2012));
setcookie('authtoken',$authtoken,mktime(0,0,0,12,31,2012));
}
The problem is everything above works fine, but the cookies won’t get set. I can see the entry being made in the database, and no errors or warnings are being thrown.
From another script, I do
var_dump($_SESSION); var_dump($_COOKIE);
I can see the session variables I set, as well as a bunch of cookies wordpress is setting, but I can’t see the cookies I just set.
Please note: The above login has nothing to do with WordPress’s login system. I’m creating my own login system.
I dont’ know why, but far too often, I figure out the answer to a problem just as I post the question to SO :/.
Anyways, got it to work by adding the remaining arguments for
setcookie. I’m going it this way now: