jumpenjuhosaphat Posted November 1, 2006 Share Posted November 1, 2006 I am trying to create a user log in feature, and I got everything fine so far, except, when a cookie is set, it doesn't take effect until the next time a page is loaded, so how do I force the page to automatically reload when I set a cookie? Link to comment Share on other sites More sharing options...
jlhaslip Posted November 1, 2006 Share Posted November 1, 2006 the cookies will not be set until you re-cycle the page or anyother one, so typically, on the successful log-in, re-direct to another page or the same one using the technique described in this posting Link to comment Share on other sites More sharing options...
jumpenjuhosaphat Posted November 1, 2006 Author Share Posted November 1, 2006 Okay, that works, but if feels a bit clumsy. Please forgive the messy coding, I'm new at this still. On all of the pages of my site, I would like to have a form that will allow a user to sign in, and have that form, when submitted, sign the user in, set a cookie, and bring them back to the same page, displaying a message as opposed to the sign in form.<? $con = mysql_connect("localhost","blahblah","blahblah"); if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("blahblah", $con);if(isset($_POST["signin"])) { $username=$_POST["username"]; $password=$_POST["password"];$result = mysql_query("SELECT * FROM user");while($row = mysql_fetch_array($result)) { if($row['username']==$username&&$row['password']==$password) setcookie("user", $row["id"], time()+3600, "/"); } }if(isset($_POST["logout"])) { setcookie("user","", time()-3600); }?><html><head><?if(isset($_POST["signin"])||isset($_POST["logout"])) echo '<meta http-equiv="Refresh" content="0;url='.$_SERVER['PHP_SELF'].'"/>';?><link rel="stylesheet" type="text/css" href="style.css"/></head><title>Hot actress</title><body><div class="main"><div class="leftside"><?if(isset($_COOKIE["user"])){ echo'<div class="welcome"></div><div class="box">'.$_COOKIE["user"].'<br/><form method="POST" action="'.$_SERVER['PHP_SELF'].'"><input type="submit" name="logout" value="Log Out"></form></div>';}else{echo '<div class="signin"></div><div class="box"><form method="POST" action="'.$_SERVER['PHP_SELF'].'">Username:<br/><input type="text" name="username"/><br/>Password:<br/><input type="password" name="password"/><br/><input type="submit" name="signin" value="Sign In"/><br/></form>Or <a href="http://www.fumbee.com/register.php">Register</a><br/>';}?></div><div class=content></div><div class="boxtop"></div></div></div></body></html> Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now