I have a login script that worked last night, made no modifications since then.
Before everyone downvotes, I have already read 10+ similar questions, but they didn't help me out.
I have a login page, with a user and pass field, when users submit, a jQuery event happens where it gets posted to a URL, and that PHP script then checks for the users existence and sets cookies if they do exist.
Here is the jQuery:
$.post('http://*******/login/', {user: $('.login-form input[name=username]').val(), pass: md5($('.login-form input[name=password]').val())}, function(data) {
if(data.status == 'success') {
setTimeout(function() {
window.location = '/dashboard.php';
}, 2000);
} else {
alert('No valid user found');
}
});
On the other end of this jQuery, is the PHP, which uses a basic API that I have built:
<?
require_once('../../classes/api.php');
$api = new API;
$username = $_POST['user'];
$password = $_POST['pass'];
if(strlen($password) != 32) {
header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error', true, 500);
die();
}
$dbCon = $api->db("***");
$checkUser = $api->login($dbCon, "users", $username, $password);
if($checkUser == false) {
echo json_encode(array('status' => 'error'));
} else {
$company = $api->getCompany($dbCon, "companies", $checkUser['company_id']);
setcookie('first_name', $checkUser['first_name'], 0, '/', '.mydomain.com');
setcookie('last_name', $checkUser['last_name'], 0, '/', '.mydomain.com');
setcookie('company_id', $checkUser['company_id'], 0, '/', '.mydomain.com');
setcookie('agency_account', $company['agency_account'], 0, '/', '.mydomain.com');
setcookie('advertiser_id', $company['advertiser_id'], 0, '/', '.mydomain.com');
echo json_encode(array('status' => 'success'));
}
?>
When I check the Chrome DevTools network section for the post, it says:
Set-Cookie:first_name=first; path=/; domain=.mydomain.com
Set-Cookie:last_name=last; path=/; domain=.mydomain.com
Set-Cookie:company_id=1; path=/; domain=.mydomain.com
Set-Cookie:agency_account=true; path=/; domain=.mydomain.com
Set-Cookie:advertiser_id=12; path=/; domain=.mydomain.com
But no new cookies are made. What could be causing this now? Like I said, it was working last night, but not today.
I am willing to add and edit the question and my code as needed.