Forum Moderators: coopster
i'm trying to get a login script working I got out of a book, I re-worked part of it to suit my needs. I keep getting the following error;
Fatal error: Call to undefined function escape_data() in /home/mrc2ect/public_html/MPA/login.php on line 24
I tried using php_flag magic_quotes_gpc inside a .htaccess file but that doesn't seem to have worked. If anybody could help me out with this it'd be much appreciated. Thanks in advance, here is the code;
<?php # Script 9.1 - login.php
// Send NOTHING to the Web browser prior to the setcookie() lines!
// Check if the form has been submitted.
if (isset($_POST['submitted'])) {
include ('common_db.php');
error_reporting(E_ALL);
$errors = array(); // Initialize error array.
// Check for an email address.
if (empty($_POST['user_id'])) {
$errors[] = 'You forgot to enter your email address.';
} else {
$e = escape_data($_POST['user_id']);
}
// Check for a password.
if (empty($_POST['password'])) {
$errors[] = 'You forgot to enter your password.';
} else {
$p = escape_data($_POST['password']);
}
if (empty($errors)) { // If everything's OK.
/* Retrieve the user_id and first_name for
that email/password combination. */
$query = "SELECT user_id, forename FROM users WHERE user_id='$e' AND password=SHA('$p')";
$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 ('user_id', $row[0]);
setcookie ('first_name', $row[1]);
// Redirect the user to the loggedin.php page.
// Start defining the URL.
$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
// Check for a trailing slash.
if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) {
$url = substr ($url, 0, -1); // Chop off the slash.
}
// Add the page.
$url .= '/loggedin.php';
header("Location: $url");
exit(); // Quit the script.
} else { // No record matched the query.
$errors[] = 'The email address and password entered do not match those on file.'; // Public message.
$errors[] = mysql_error() . '<br /><br />Query: ' . $query; // Debugging message.
}
} // End of if (empty($errors)) IF.
mysql_close(); // Close the database connection.
} else { // Form has not been submitted.
$errors = NULL;
} // End of the main Submit conditional.
// Begin the page now.
$page_title = 'Login';
include ('./includes/header.html');
if (!empty($errors)) { // Print any error messages.
echo '<h1 id="mainhead">Error!</h1>
<p class="error">The following error(s) occurred:<br />';
foreach ($errors as $msg) { // Print each error.
echo " - $msg<br />\n";
}
echo '</p><p>Please try again.</p>';
}
// Create the form.
?>
<h2>Login</h2>
<form action="login.php" method="post">
<p>Username: <input type="text" name="username" size="20" maxlength="40" /> </p>
<p>Password: <input type="password" name="password" size="20" maxlength="20" /></p>
<p><input type="submit" name="submit" value="Login" /></p>
<input type="hidden" name="submitted" value="TRUE" />
</form>
<?php
include ('./includes/footer.html');
?>