Wednesday 12 September 2012

PHP ( Tutorials I )


PHP Authenticate

Simple coding of securing page in PHP.

If you want to login in the permission base,mean same page open in the many password then to use a following Code.This code Save in PHP and run to the localhost server.The below code has three username and password combinations. A function has also been added that will be used to check if a user has been logged in and will be used to authenticate many user on same page to login......

This code Save the name of  password.php and run the localhost server. 

<?php

$v=sha1('pass1');

Echo $v;

?>


Shown below code save a text file and you want to create a many password in the same method but  you  to change the value of pass1 every time and the output is different -2....

output is:9e5ca6b0ffb417997ffb844c76f9c24bbc20fe88


Then to use a following code and save the password_login.php......

<?php

$authorized_user=FALSE;

if (isset($_SERVER['PHP_AUTH_USER']) && isset ($_SERVER['PHP_AUTH_PW']))

{

$autharray=file("http://URL.txt");

foreach($autharray as $row) {

list ($user,$pswd)=explode(":",$row);

$pswd=trim($pswd);

if (($_SERVER['PHP_AUTH_USER']==$user) &&

(sha1($_SERVER['PHP_AUTH_PW'])==$pswd))  {

$authorized_user=TRUE;

break;

}   

}

}

if (!$authorized_user)  {

header('www-authenticate:basic realm="Photo album" ');

header('Http/1.0  401 unauthorized');

print "invalid user name and password ! ";

exit;

}

else

echo "Welcome <br>";

?>

0 comments:

Post a Comment