Ok for the above question i have came accross the following code
- PHP: Select all
<?php
session_start();if ( $log_out )
{
session_unregister( "valid_user" );
session_destroy();
session_start();
}
function write_log_in( $text )
{
echo "
$text
<form method='post' action=''><br />
<p>User ID: <input type='text' name='user_name/><br />
<p>Password: <input type='password' name='password'/><br />
<p><input type='submit' value='Log In'/><br/>
</form>
";
} // end write_log_in function
function verify()
{
// check to see if they’re already logged in
if ( session_is_registered( "valid_user" ) ) return true;
// check to see if visitor has just tried to log on
$user_name = $_POST["user_name"];
$password = $_POST["password"];
if ( $user_name && $password )
{
// verify password and log in to database
$db = mysql_pconnect( "localhost", "$user_name", "$password" );
if ( $db )
{
// register session variable and exit the verify function
$valid_user = $user_name;
$_SESSION['valid_user'] = $valid_user;
return true;
}
else
{
// bad user and password
$text = "User Name and Password did not match";
write_log_in( $text );
}
}
else
{
// user must log in
$text = "This is a secure server. Please log in.";
write_log_in( $text );
}
} // end verify function
?>
<html>
<head>
<title></title>
<body>
<?php
// check for valid user
if ( verify() )
{
echo "
Log out";
// begin secure content
echo "
Clatu, verata, nicto
";
// end secure content
} // end if ( verify() )
?>
</body>
</html>
This code will work but the problem i have is i want to add the fuction:
- PHP: Select all
select = "select user_name from users
where user_name='$user_name'
and password=PASSWORD( '$password' )";
$query = mysql_query( $select );
if ( mysql_num_rows( $query ) == 1 )
{
// validated user and password
How would i do this?
Thanks
Robert