User Register and Login
Posted: Tue May 31, 2011 10:03 am
Hello, I finished off the User Register and Login tutorial and it all worked fine, i moved onto Email activation one and i got some errors.
When i register it all works fine, the user is added to the users table but the activation isn't added to the user_activation table.
The activation email is sent fine.
The error i am getting is:
My login.php:
[syntax=php]<?php
include('core/init.inc.php');
$errors = array();
if (isset($_POST['username'], $_POST['password'])) {
if (empty($_POST['username'])) {
$errors[] = 'The username cannot be empty.';
}
if (empty($_POST['password'])) {
$errors[] = 'The password cannot be empty.';
}
if (valid_credentials($_POST['username'], sha1($_POST['password'])) === false) {
$errors[] = 'Username / Password incorrect.';
}
if (empty($errors) && is_active($_POST['username']) === false) {
$errors[] = 'This account has not yet been activated.';
}
if (empty($errors)) {
$_SESSION['username'] = htmlentities($_POST['username']);
header('Location: protected.php');
die();
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> <?php echo $sitetitle; ?> </title>
</head>
<body>
<div class="error">
<?php
if (empty($errors) === false) {
?>
<ul>
<?php
foreach ($errors as $error) {
echo "<li>{$error}</li>";
}
?>
</ul>
<?php
} else {
echo 'Need an account? <a href="register.php">Register</a>.';
}
?>
</div>
<form action="" method="POST">
<p>
<label for="username">Username:</label>
<input type="text" name="username" id="username" value="<?php if (isset($_POST['username'])) echo htmlentities($_POST['username']); ?>" />
</p>
<p>
<label for="password">Password:</label>
<input type="password" name="password" id="password" />
</p>
<p>
<input type="submit" name="submit" value="Register" />
</p>
</form>
</form>
</body>
</html>[/syntax]
If you need anymore code please reply. I know this is probably going to be a misspelt word or just missing a symbol or something. I have looked through it all and i can't notice any errors. I hope someone else can.
When i register it all works fine, the user is added to the users table but the activation isn't added to the user_activation table.
The activation email is sent fine.
The error i am getting is:
Fatal error: Call to undefined function valid_credentials() in /home/tomwign/public_html/hackergame/login.php on line 16
My login.php:
[syntax=php]<?php
include('core/init.inc.php');
$errors = array();
if (isset($_POST['username'], $_POST['password'])) {
if (empty($_POST['username'])) {
$errors[] = 'The username cannot be empty.';
}
if (empty($_POST['password'])) {
$errors[] = 'The password cannot be empty.';
}
if (valid_credentials($_POST['username'], sha1($_POST['password'])) === false) {
$errors[] = 'Username / Password incorrect.';
}
if (empty($errors) && is_active($_POST['username']) === false) {
$errors[] = 'This account has not yet been activated.';
}
if (empty($errors)) {
$_SESSION['username'] = htmlentities($_POST['username']);
header('Location: protected.php');
die();
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> <?php echo $sitetitle; ?> </title>
</head>
<body>
<div class="error">
<?php
if (empty($errors) === false) {
?>
<ul>
<?php
foreach ($errors as $error) {
echo "<li>{$error}</li>";
}
?>
</ul>
<?php
} else {
echo 'Need an account? <a href="register.php">Register</a>.';
}
?>
</div>
<form action="" method="POST">
<p>
<label for="username">Username:</label>
<input type="text" name="username" id="username" value="<?php if (isset($_POST['username'])) echo htmlentities($_POST['username']); ?>" />
</p>
<p>
<label for="password">Password:</label>
<input type="password" name="password" id="password" />
</p>
<p>
<input type="submit" name="submit" value="Register" />
</p>
</form>
</form>
</body>
</html>[/syntax]
If you need anymore code please reply. I know this is probably going to be a misspelt word or just missing a symbol or something. I have looked through it all and i can't notice any errors. I hope someone else can.