WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search


Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder



Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : A simple PHP 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.
Categories : PHP, Sessions, Security, Authentication
ROMEL CUZON
Date : Jun 28th 2004
Grade : 3 of 5 (graded 42 times)
Viewed : 251626
File : 3927.zip
Images : No Images for this code example.
Search : More code by ROMEL CUZON
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

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>



Authenticator for Exchange Server LDAP
Categories : PHP, Authentication, LDAP, Security, Sessions
Form Security - Match A Value For Success
Categories : PHP, Authentication, HTML and PHP, Sessions, 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
A login page that require username, password and userlevel.
Categories : PHP, Security, Sessions, MySQL, Databases
Use of bitmasks to represent permissions
Categories : PHP, Authentication, Bitwise Operators, Security, PHP Classes
Simple Password example
Categories : PHP, Authentication, Security, HTTP
MD5 secured login
Categories : PHP, Java Script, Authentication, Security
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
session out Timer
Categories : PHP, Sessions, Security, Beginner Guides
Function to generate readable/remeberable random password
Categories : PHP, Security, Security
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
CAPTCHA[Image verification]
Categories : PHP, Security, GD image library, Graphics, Sessions
Securing Web Forms with Simple PHP-CAPTCHA (Completely Automated Public Turing test to tell Computers and Humans Apart)
Categories : PHP, Security, GD image library, Sessions
Session Validation Methods (Security Checks)
Categories : PHP, Sessions, Security
Basic Authentication with sessions
Categories : PHP, Beginner Guides, Authentication, Form Processing, Sessions
 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.)