Hi
I am trying to adapt a script that I found, and I am having a bit of trouble. What I want to do is simply to set the cookie for the login and then redirect the person to the logged in page. Here is the script I am using, can anyone see what might be wrong here.
Thanks,
Philweb
if (isset($_POST['submit'])) { // Handle the form.
require_once ('./mysql_connect.php'); // Connect to the db.
// Create a function for escaping the data.
function escape_data ($data) {
global $dbc; // Need the connection.
if (ini_get('magic_quotes_gpc')) {
$data = stripslashes($data);
}
return mysql_real_escape_string($data, $dbc);
} // End of function.
$message = NULL; // Create an empty new variable.
// Check for a username.
if ($u && $p) { // If everything's OK.
// Retrieve the user_id and first_name for that username/password combination.
$query = "SELECT user_id, first_name FROM employees WHERE first_name='$fn' AND email='$e'";
$result = @mysql_query ($query); // Run the query.
$row = mysql_fetch_array ($result, MYSQL_NUM); // Return a record, if applicable.
if ($row) { // A record was pulled from the database.
// Set the cookies & redirect.
setcookie ('first_name', $row[1]);
setcookie ('user_id', $row[0]);
header ("Location: http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/login.php");
exit(); // Quit the script.
} else { // No record matched the query.
$message = '<p>The first name and email entered do not match those on file.</p>';
}
mysql_close(); // Close the database connection.
}
} // End of the main Submit conditional.
// Set the page title and include the HTML header.
$page_title = 'Login';
// Print the error message if there is one.
if (isset($message)) {
echo '<font color="red">', $message, '</font>';
}
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
Enter your information in the form below:
<p><b>First Name:</b> <input type="text" name="username" size="10" maxlength="20" value="<?php if (isset($POST['first_name'])) echo $POST['first_name']; ?>" /></p>
<p><b>Email:</b> <input type="text" name="password" size="50" maxlength="100" />
</p>
<div align="center"><input type="submit" name="submit" value="Login" /></div>
</form