I've reviewed a lot of posts on this subject already, but my code doesnt quite seem to be setting any cookies.
so my initial ajax call is something like this:
$("#loginForm").submit(function(event) {
event.preventDefault();
var uid = document.getElementById("userLogin").value;
var pid = document.getElementById("passLogin").value;
var url = "../_scripts/loginScript.php";
$.ajax({
type: "POST",
url: url,
datatype : "script",
data: {user: uid, pass: pid},
success: function(msg) {
if( strcmp(msg,"passwords are equal") )
location.reload();
else
$('#error1').html(msg).show(100);
}
});
});
where i wrote the strcmp()
function in a different js library.
after doing a bunch of hashing and salting stuff my php looks something like:
<?php
if($hashPass == $pass)
{
echo "passwords are equal";
$cookieInfo = $_POST['user'].",".$clearance;
setcookie("loggedIn", $cookeInfo,0,"/");
exit;
}
else
{
echo "Invalid password";
exit;
}
?>
when i test it out, the "passwords are equal" message comes back and the page gets reloaded... but my cookie never gets set when i check my browser.
I'm not sure what I'm doing wrong... I've used this code before when I used a form to submit directly to a php file and it works fines, but now that I'm using ajax the cookie doesnt seem to get set.
Is it because I'm not setting the cookie after a header("Location: ...");
call..?