View Single Post
  #11 (permalink)  
Old Mar 29th, 2007, 18:30
robukni robukni is offline
Up'n'Coming Member
Join Date: Jan 2006
Location: NI
Posts: 50
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Username & Password

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 ) == )
{
// validated user and password 
How would i do this?

Thanks
Robert

Last edited by karinne; Mar 30th, 2007 at 15:00. Reason: Please use [php]...[/php] tags when displaying code!
Reply With Quote