Login Script with Sessions
Posted: Tue Oct 26, 2004 3:40 pm
I'm trying to make a login page with sessions. I'm not understanding where the problem is. ANy help is really appreciated.
Code: Select all
<?php
//if they haven't pressed the submit button, then show the form
if(!$submit)
{
echo "<html><head><title>My Login Form</title></head><body>";
echo "<form name="l1" action=$_SERVER[PHP_SELF] method="post">";
echo "<div>Username: <input type="text" name="username" /><br />";
echo "Password: <input type="password" name="password" /><br />";
echo "<input type="submit" name="submit" value="Login" /><br />";
echo "</div></form></body></html>";
}
else //otherwise, let's process this stuff
{
if($username == "user" && $password == "mypass") //if they got it right, let's go on
{
session_start();
session_register("mysessionvariable"); //set a variable for use later
$id = session_id(); //let's grab the session ID for those who don't have cookies
$url = "Location: page2.php?sid=" . $id;
header($url);
}
/*else //they got something wrong and we should tell them
{
echo "<html><head><title>My Login Form</title></head><body>";
echo "<span style="color:#ff0000;">Password/Username Is Invalid</span><br />";
echo "<form action="<?$PHP_SELF?>" method="post">";
echo "<div>Username: <input type="text" name="username" /><br />";
echo "Password: <input type="password" name="password" /><br />";
echo "<input type="submit" name="submit" value="Login" /><br /></div></form>";
echo "</body></html>";
}*/
}
?>