I scrapped that code, I think this is more secure..
Here's the code.
<?php
//session_start();
ob_start();
$username = protect($_POST['username']);
$password = $_POST['password'];
$errors[] = array();
if(!$username){
$errors[] = "You did not supply a username!";
}
if(!$username){
$errors[] = "You did not supply a password!";
}
if(count($errors) >= 1){
echo "The following error(s) occured:<br>\n";
foreach($errors AS $error){
echo $error . "<br>\n";
}
}else {
$sql = "SELECT * FROM `users` WHERE `username`='".$username."'";
$res = mysql_query($sql) or die(mysql_error());
if(mysql_num_rows($res) == 0){
echo "The username you supplied does not exist!";
}else {
$sql2 = "SELECT * FROM `users` WHERE `username`='".$username."' AND `password`='".md5($password)."'";
$res2 = mysql_query($sql2) or die(mysql_error());
if(mysql_num_rows($res2) == 0){
echo "Username and password combination incorrect!";
}else {
$row = mysql_fetch_assoc($res2);
// we're going to set the user id
// for cookies
setcookie('id',$row['uid'],time()+86400);
// for sessions
$_SESSION['uid'] = $row['id'];
header("Location: my_account.php");
}
}
}
ob_end_flush();
?>
My error is
Call to undefined function protect() in C:\wamp\www\forum\login.php on line 5