|
|
|
|
|
|
| |
A simple login script that you can modify to suite your needs. It use a session to store data in a session file submited by the page. In this example the username and password will be save in the session file created by php.
I introduce the following files.
index.php -script file as name of your protected site.
login.html -script file as your login page.
user -folder
test.txt -account file under folder(user)
test|password -the content of the test.txt, username is test password is password
What you are going to do?
1. In your php.ini, enable session.use_cookies and specify session.save_path
2. Create a folder name "user" under it create an account file example: "test.txt"
3. The content of your test.txt will be like this
test|password
*note
account filename is the same as username.
5.copy the script and place it to your web directory.
4.edit the index.php and change the $root=to the actual full path where folder(user) is located.
5.and insert the code of your protected website as shown in the script.
<!//your script starts here when account is valid--->
<! insert your code here.....---->
Password Protected Website<br>
YOU ARE LOGIN AS <? echo $username ?> <br>
<a href=<?php echo"$SCRIPT_NAME";?>?logout=1>Logout</a>
<!//your script ends here--->
6:login and use test as username and password as password.
| <?php
$root="c:/inetpub/wwwroot/romel/"; //full path of folder(user)
session_start();
$_SESSION['username'] = $username;
$_SESSION['password'] = $password;
//if (isset($logout))
//{
if ($logout==true)
{
unset($HTTP_SESSION_VARS['username']);
unset($HTTP_SESSION_VARS['password']);
echo"<meta http-equiv=refresh content=\"0;URL=$SCRIPT_NAME\">";
}
//}
if (file_exists($root."user/".$username.".txt"))
{//1
$fp=fopen($root."user/".$username.".txt","r");
$contents=fread($fp,filesize($root."user/".$username.".txt"));
fclose($fp);
$info=explode("|",$contents);
$username1=$info[0];
$password1=$info[1];
if($password1==$HTTP_SESSION_VARS['password'])
{//2
?>
<!//your script starts here when account is valid--->
<! Insert your code here ---->
Password Protected Website<br>
YOU ARE LOGIN AS <? echo $username ?> <br>
<a href=<?php echo"$SCRIPT_NAME";?>?logout=1>Logout</a>
<!//your script ends here--->
<?php
}//2
else
{//2
$err="Invalid Password";
include("login.html");
unset($HTTP_SESSION_VARS['username']);
unset($HTTP_SESSION_VARS['password']);
session_destroy();
}//2
}//1
else
{
$err="Invalid Username";
include("login.html");
unset($HTTP_SESSION_VARS['username']);
unset($HTTP_SESSION_VARS['password']);
session_destroy();
}
?>
login.html
<html>
<head><title>login</title></head>
<body bgcolor=gold>
<center>
<form method=post action=<? echo "$SCRIPT_NAME"; ?>>
<table border=1 cellpadding=3 celspacing=3 align=center width=50%>
<tr><td colspan=2 align=center>Login</td></tr>
<tr><td colspan=2 align=center><?php if (isset($username)){if ($logout==false){if(isset($err)){echo "$err";}}}?></td></tr>
<tr><td>Username:</td><td><input type=text name=username size="20"></td><tr>
<tr><td>Password:</td><td><input type=password name=password size="20"></td><tr>
<tr><td colspan=2><input type=submit></td><tr>
</table>
</form>
</body>
</html> | | |
|
| Form Security - Match A Value For Success Categories : PHP, Authentication, HTML and PHP, Sessions, Security | | | Authenticator for Exchange Server LDAP Categories : PHP, Authentication, LDAP, Security, Sessions | | | Basic Authentication with sessions Categories : PHP, Beginner Guides, Authentication, Form Processing, Sessions | | | Simple Password example Categories : PHP, Authentication, Security, HTTP | | | PHP Function to Encrypt/Decrypt a string without a known key. The string itself has his own different key for every character. Categories : PHP, Algorithms, Security, Authentication, Encryption | | | MD5 secured login Categories : PHP, Java Script, Authentication, Security | | | A damaged image generator (class) for validating text.
CAPTCHA - Completely Automated Public Turing test to tell Computers and Humans Apart Categories : PHP, PHP Classes, Security, GD image library, Security | | | Session Validation Methods (Security Checks) Categories : PHP, Sessions, Security | | | Password using php, Javascript, and html form Categories : Security, PHP, Authentication, Java Script | | | CAPTCHA[Image verification] Categories : PHP, Security, GD image library, Graphics, Sessions | | | phpSecurePages is a PHP module to secures pages with a loginname and
password. It handles multiple user groups (each has own viewing rights),
store data in a MySQL database or a configuration file, and can be used to
identify Web site viewers. Categories : PHP, Security, Authentication | | | Use of bitmasks to represent permissions Categories : PHP, Authentication, Bitwise Operators, Security, PHP Classes | | | session out Timer Categories : PHP, Sessions, Security, Beginner Guides | | | Password protection for Phorum 3.1.x with userlevels and log. Categories : PHP, MySQL, Authentication, Security | | | A login page that require username, password and userlevel. Categories : PHP, Security, Sessions, MySQL, Databases | |
| | | | Jose Santos wrote :1140
Autentication and Security in the web is each time more useful !!
I something, recomend to use php sessions and encrypt theses password for best security !
Other good choose, is to devellop scripts that works in diferent plataforms (windows, linux, etc.)
| |
|
|
|