I have the following code:
<?php
require_once 'assets/functions.php';
if(isset($_SESSION['userName'])){
header('Location:http://192.168.0.50/hub.php');
die();
}
$title = 'ResRes - Login';
printCSS($title);
?>
Which is part of my index.php file. The problem is that after loading, neither window.location = result.location
or the header('Location:http://192.168.0.50/hub.php')
work. This is getting quite frustrating.
My javascript code is:
function verifyUser(userEmail){
$.getJSON('verifyUser.php', {data : userEmail}
).done(function(result){
window.location.href = result.location;
alert(result.message);
console.log(result);
return false;
});
};
I suspect that the .done(function(result){...})
is not even executing, since no console.log() occurs nor the alert itself. No idea why it is having that behaviour.
Also, just to make sure, in my verifyUser.php file I have the following header:
header('Content-Type: application/json');
On the test server, and on wamp server this does not happen. It gets redirected. In this production server, however, it does not redirect. User has to manually refresh the page to be sent to result.location
or what the header on index.php says.
Any ideas what might be happening?
EDIT Perform the $.getJSON
manually on console, outputs this:
$.get('verifyUser.php', {data : 'hector.admin@laestanciaschool.com'}).done(function(result) { console.log("Done called", result); });
Object {readyState: 1, getResponseHeader: function, getAllResponseHeaders: function, setRequestHeader: function, overrideMimeType: function…}
Could you try replacing
window.location.href = result.location
with
window.open(result.location, "_self")
Also, do you have sessions enabled in your php.ini file?
You could use the js debugger of your browser to insert breakpoint to see what's wrong.
With chrome, press F12
and click the Sources
Tab, and then find you source file, insert breakpoint by left-clicking the left-side of the line of code.
You could also check the request and response between the browser and your server with the Network
Tab