I am creating a cloud based php application and When I use the code below in the top of my PHP document it creates the cookie perfectly.
setcookie("lgUsr",'admin', time() + (3600 * 24 * 30), "/");
But when I put it like below as a form submission it does not create the cookie in the browser.
<?php
if(isset($_POST['login-submit'])){
$usrName = $_POST['username'];
if($usrName == 'admin'){
setcookie("lgUsr",'admin', time() + (3600 * 24 * 30), "/");
?>
<script>
var resP = document.getElementById('result');
resP.classList.add('success-text');
resP.innerHTML = 'Successfully Logged In.';
</script>
<?php
header("Location: admin-dashboard.php");
} else{
?>
<script>
var resP = document.getElementById('result');
resP.classList.add('error-text');
resP.innerHTML = 'Error Occured while logging in.';
</script>
<?php
}
}
?>
What could be the problem? Any kind of help is really appreciated. Both codes above works perfectly in the localhost, GAE is the one that gives the problem.