I did this code to validate if the user is logged using cookie, but my cookie disappear when i click to any link of my web site, anybody can check where is the issue?
<?php if ( (isset($_POST["login"])) and (isset($_POST["senha"])) ) { if (preg_match("/<div[^>]*>" . preg_quote(trim($_POST["login"]),"/") . ";" . preg_quote(trim($_POST["senha"]),"/") . ";([^;]*?)<\/div>/",strip_tags(html_entity_decode( file_get_contents("paginas/area-restrita.php")),"<div>"),$resultado)) { $resultado[1] = "area-restrita-" . strtolower($resultado[1]); setcookie("area-restrita",md5($resultado[1]),time() + 60*60); ?><script type="text/javascript"> window.location = "http://empresasite.com.br/index.php?q=<?php echo $resultado[1]; ?>";</script><?php } else{ usleep(2000000); ?><script type="text/javascript"> alert("Login/Senha não conferem."); window.location = "http://empresasite.com.br/index.php"; </script><?php } } else if ( (isset($_GET["q"])) and (strpos($_GET["q"],"area-restrita-") !== false) ) { if (!isset($_COOKIE["area-restrita"])) { ?><script type="text/javascript"> alert("Você deve fazer login para acessar essa página."); window.location = "http://empresasite.com.br/index.php"; </script><?php } else if (md5($_GET["q"]) != $_COOKIE["area-restrita"]){ ?><script type="text/javascript"> alert("Você não deveria fazer isso."); window.location = "index.php"; </script><?php } else{ $q = $_GET["q"]; } }