No logro hacer que me deje la cookie
Código PHP:
<script type="text/javascript">
function sesion(){
var user=document.getElementById('username').value;
var password=document.getElementById('password').value;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("loginframe").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","login2.php?u="+user+"&p="+password,true);
xmlhttp.send();
}
</script>
<div id='loginframe'>
<?
if(isset($_COOKIE["4ourelementsuser"])){
$user1=$_COOKIE["4ourelementsuser"];
echo $user1;
}
?>
<h2>Miembros</h2>
<form action="index.php" method="post" name="FormLogin">
<label>Usuario</label>
<input type="text" value="" name="username" size="10" class="input_field" id="username" />
<label>Password</label>
<input type="password" value="" name="password" class="input_field" id="password" />
<input type="submit" value="Login" id="submit_btn" onClick="sesion()" title="Login" />
</form>
</div>
y el login2.php es:
Código PHP:
<?
$username=$_GET["u"];
$password=$_GET["p"];
$action=$_GET["action"];
require('config.php');
if($username!=NULL and $password!=NULL){
$u=mysql_query("SELECT user FROM tb_users WHERE user='$username'");
$u2=mysql_num_rows($u);
if($u2>0 and action!="logout"){
setcookie("usermiweb",$username,time()+86400);
echo'sesioniniciada';
}
}else{
echo'<br>error';
}
if($action=="logout"){
setcookie("4ourelementsuser",$username,time()-86400);
}
?>