I'm developing a login form using an ajax calling.
First of all, I have my HTML code that comes below this paragraph
<form id="login_form" name="login" method="POST"> <input id="login_email" name="login_email" type="text" placeholder="Email" /> <input id="login_password" name="login_password" type="password" placeholder="password" /> <input id="login_checkbox" name="login_remember" type="checkbox" /> <input type="submit" /> </form> After verifying with JQuery all the errors in the client, I do an ajax calling like the code below.
$.ajax({ url: '../ajax/login.php', cache: false, type: "POST", data: $( "#login_form" ).serialize(), dataType: 'json', success: function(data){ if (!data){ //Logged correctly! window.location = "../page/colabora"; } }); Then, login.php has been called... and here is the problem. I try to set a cookie like setcookie('usr', $value) with the id of the client logged but there's no cookie comming back.
Checking colabora.php, it doesn't bring any cookie as a callback response.
Where could be the problem?
Thanks in advice
UPDATE
I should have been more specific with the ajax calling.... My script takes the form comming bellow.
// Our custom secure way of starting a PHP session. $secure = false; // This stops JavaScript being able to access the session id. $httponly = true; // Forces sessions to only use cookies. if (ini_set('session.use_only_cookies', 1) === FALSE) { header("Location: ../page/serror?err=-2"); exit(); } // Gets current cookies params. $cookieParams = session_get_cookie_params(); session_set_cookie_params($cookieParams["lifetime"], $cookieParams["path"], $cookieParams["domain"], $secure, $httponly); // Sets the session name to the one set above. session_name('sec_session_id'); session_start(); // Start the PHP session session_regenerate_id(); // regenerated the session, delete the old one. setcookie('usr', 'example_cookie'); UPDATE 2
After a lot of time and many time wasted trying to find a solution, I just decided to record an aux session param in the login.php and record the cookie in colabora.php when the user has been successfully conected.
session_start()for sure!