Your JavaScript redirect is wrong. You have document.location
it should be window.location
. $_REQUEST
is not depreciated, but you do have to make sure you are using it correctly. If your form is being submitted, make sure you test for your submit button being set. Really your code should look more like this, if you are using the $_POST
method, which is more secure:
<?php
session_start();
if(isset($_POST['submitButton']) && isset($_COOKIE['ok']) && $_COOKIE['ok'] === '1'){
setcookie('user', $_POST['name_theuser']);
setcookie('tipe', $_POST['thetipe']);
//send a header or do your thing here
}
else{
header('LOCATION:disconnect.php'); die();
}
?>
I was also unclear why you were trying to do a redirect, no matter what, at the bottom of your page.
Side Note:
You do not have to use window.location.href =
. You can actually just use window.location =
as a shortcut. Shorter yet, you can actually just use location =
, because window
is implicit.