Well, I'm still a newbie programming PHP... but I already read several ebooks and another book I have.... still unable to fix this issue.
What I'm trying to do is login system, but the cookie is unable to be set.
I tried writting the code on a separate file, and it doesn't work.
This is the code I currently have (named usuario.php)
code:
<?php
error_reporting(E_ALL);
require('./inc/connect.php');
echo ("<br /> Webaction: ".$webaction."<br />");
echo ($_COOKIE['lagoweb[username]']);
//Desloguea al usuario
if ($webaction == "logout") {
echo ("Testing logout");
setcookie('lagoweb[username]');
}
//Procesa la forma de login
elseif ($webaction == "login") {
if (isset($_COOKIE['lagoweb[username]'])) {
echo "You are already logged in!, do you want to <a href=usuario.php?webaction=logout>logout</a>?";
} else {
echo ("<form method='POST' class='loginform'><table><tr><td>Usuario:</td><td><input type='text' name='username'></td></tr><tr><td>Contraseña:</td><td><input type='password' name='password'></td></tr><tr><td><input type='submit'></td></tr><tr><td><input type='hidden' value='do_login' name='webaction'></td></tr>
</table></form>");
}
}
//Proceso de inicio de sesion
elseif ($webaction == "do_login") {
$dbquery = mysql_query("SELECT * FROM users WHERE username = '$username' AND password = '$password'") or die (mysql_error);
if (mysql_num_rows($dbquery) == 1) {
setcookie("lagoweb[username]",$username,time()+3600);
echo "Success!";
} else {
echo "Failed";
}
}
?>
Any help will be greatly appreciated.
Thanks in advance.