My login page: (login.php)
Code: Select all
<"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmls = "http://www.w3.org/1999/xhtml">
<head>
<title>Login Page</Title>
<link rel=stylesheet href="default.css" type="text/css">
<?php
$log = $_cookie['login'];
if (($log != "") && ($survey == "yes"))
{
header('location: surveyform.php?survey=yes&loggedin=yes');
}
?>
</head>
<body>
<p>
<h2>Login:</h2>
</p>
<form action = "surveyform.php" method = "post">
<p>
Username:
<input type="text" name="username">
</p>
<p>
Password:
<input type="password" name="password">
</p>
<p>
<input type="submit" value="Submit">
</p>
<?php
if ($survey=="yes")
print "<input type='hidden' name='survey' value='yes'>";
?>
<p><a href="register.html"><h2>Register Today!</h2></a></p>
Now, this script is the one I need to set the cookies: (surveyform.php)
Code: Select all
<?php
$loggedIn = false;
$file = fopen("members.dat", "r");
if(!feof($file))
{
$fileContents = fread($file, filesize("members.dat"));
$loginPairs = explode("\n", $fileContents);
foreach($loginPairs as $loginPair)
{
if(strstr($loginPair, $_POST["username"]))
{
$loginInfo = explode("|", $loginPair);
if($loginInfo[1] == $_POST["password"])
{
$loggedIn = true;
break;
}
}
}
if(!$loggedIn)
{
echo "<h2>The credentials you supplied could not be
found.</h2>";
die();
}
}
else
{
echo "Could not open <b>members.dat</b> for reading!";
}
?>
I have to check the value of $loggedin. If it's not equal to "yes", you need to set two cookies:
1.) Name register, value of firstname, and expiration of 1 week
2.) Name login, value of firstname, and expiration of 1 hour.
I then have to check the value of $survey. If its not equal to "yes", you should redirect the user to the welcome page.