jlr2k8 Posted September 6, 2006 Share Posted September 6, 2006 Ok, so I'm making (or I guess... attempting to make :D) this login system using PHP. The login script, assuming the user is successfully authenticated, will generate a cookie with the username and a cookie with the password.Here is part of the validation script:[code]if($_POST['password'] != "$password"){ header("cache-control: no-cache, must-revalidate"); header("location: ../user.php?content=l&s=f"); //redirect to login page, with a failure notification}else{ $userName = $_POST["userName"]; $password = $_POST["password"]; setcookie("WFS2U", $userName); setcookie("WFS2P", $password); header("cache-control: no-cache, must-revalidate"); header("location: ../index.php"); //redirect to home}[/code]Then to display the cookies, I use: [code]echo $_COOKIE["WFS2U"];[/code]I use PHP 5 which runs on IIS 6.0.Thanks for your help,Josh Rogers Quote Link to comment Share on other sites More sharing options...
btherl Posted September 6, 2006 Share Posted September 6, 2006 It might be a path issue. Try:[code]setcookie("WFS2U", $userName, time()+60*60*24, '/')[/code]That time()+60*60*24 sets it to expire in 1 day. You have to include an expiry time in order to set the cookie path (yes, it doesn't make sense, it's because of the argument order).Also, remember that $_COOKIE[] only contains cookies received from the browser. You will only see these in the NEXT request, and not in the same request that you set the cookie. Quote Link to comment Share on other sites More sharing options...
jlr2k8 Posted September 6, 2006 Author Share Posted September 6, 2006 Hmm I noticed something though. The cookie only sets if I don't have header() on the same page. Why is that? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.