Jump to content

User Log in, how to refresh


jumpenjuhosaphat

Recommended Posts

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...