i have been trying to create a php login form.. though i have failed. i need to know what is wrong and why it iis not working if correct user name and pass it will set a cookie. code is below : ----------------------- <?php if (isset($_COOKIE['sugar'])) { echo "welcome back!"; die; } else { if (isset($_POST['submit']) && !empty($_POST['user']) && !empty($_POST['password'])) { if ($_POST['user'] = "user" && $_POST['password'] = "pass") { $cookie = setcookie("sugar", "sugar", time()+1000000000000, "/", "smarticals-and-cheese.site88.net", 0); setcookie("sugar", "sugar", time()+1000000000000, "/", "smarticals-and-cheese.site88.net", 0); if ($cookie === true) { echo "cookie was set no need to login again <br />"; } else { echo "cookie was not set please enable cookies"; } echo "login success"; } else { echo "login failed"; } } else { ?> <html> <body> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> Username:<input type="text" name="user" /> <br /> Password: <input type="password" name="password" /> <br /> <input type="submit" name="submit" value="submit" /> </form> </body> </html> <?php } } ?> though i already have a login form i just want to see why this won't work.
For first sight I think that the problematic part of the code is the $cookie comparison PHP: if ($cookie === true) . You should try somehow like this PHP: if(isset($_COOKIE["sugar"]))