Free web development scripts for the webmasterDevelopment Scripts


 
 Site Navigation
 o Development Scripts
 o Text Only Edition
 o PHP.net News
 o Tutorials
 o Register an account
 o New entries this week
 o Affiliates/Links
 o Contact Us
 o About us
 o Advanced Search

 Browse Path
 o 1 user online
 o Most users online: 67
 o Home
  o PHP
   o Cookies/Sessions
    o Script

 Member Login
User Name
Password

 Standards
Valid XHTML 1.0!
Valid 
CSS!

 Recommended Links
 o PHP Freaks
 o Designer Baby Clothes
 o White Watch Store
 o iPad 64gb 3g
 o Invoice Software
 o Free Wedding Websites
 o UK Business Franchises
 o Invoice Software
 o OxyScripts

User Login System with Sessions (Rated 5)

Description:

You can use this script to see how to log someone onto your site.

It uses sessions, but could easily be adapted for using cookies as well if required.

This is particularly useful for allowing users to add news etc to your site, or just to allow them to vote on news etc etc

Code starts here


<?PHP session_start(); ?>

<form action="index.php" method="post">
<table width="100%" border="0" cellspacing="0" cellpadding="4">
<tr>
<td><div class="small" align="right">User Name</div></td>
<td><input name='username' type='TEXT' id="username" value="" maxlength='20'></td>
</tr>
<tr>
<td><div class="small" align="right">Password</div></td>
<td><input name="password" type="password" id="password" value=""></td>
</tr>
<tr>
<td><div align="center"></div></td>
<td><div align="left"><input type="submit" name="userlogin" value="Login"></div></td>
</tr>

</table>
</form>

<?PHP
// check login and password
// connect and execute query
// db_connect is a script which provides a bd connection
include_once('db_connect.php');

if(isset(
$_POST['userlogin']))
{
$username = strip_tags($_POST['username']) ;
$password = md5($_POST['password']) ;
$query = "SELECT UserID, UserName, Password from UserTable WHERE username ='$username' AND password = '$password'";
$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());

// if row exists - login/pass is correct
if (mysql_num_rows($result) == 1)
{
list(
$id, $username, $password) = mysql_fetch_row($result);
// initiate a session
// as we gonna log the user in too

// register the user's ID
session_register('UserID');
session_register('Username');

$_SESSION['UserID'] = $id;
$_SESSION['Username'] = $username;
// Redirect them as logon sucessful
}
else
// login/pass check failed
{
// Handle the bad logon
}
}
?>


Submitted by Devscripts on 07-03-2003 14:22


Recent Additions (from all categories)

(PHP) T Shirt Printing Software

(PHP) Youtube Video Organizer Script

(PHP) MP3z - MP3 Search Engine Script

(PHP) Recipez- PHP Recipe Script

(ASP) Stop image hotlinking and downloading. Web image protection is easy with Image Trapper.

Top Rated Scripts

(Javascripts) Javascript Delayed Redirection Rating: 5

(PHP) Random Links and images with PHP & MySQL Rating: 5

(PHP) RSS/XML news feed headline grabber! Rating: 5

(PHP) Random Signatures/Avatars Rating: 5

(Javascripts) Detecting Client Web Browser Rating: 5

© Copyright 2003 - Devscripts.net