Forgot Password / Register
Site Statistics
Total Members: 509
Total Tutorials: 242
Newsest User: Lestop
Todays Unique Hits: 155
0 Users 1 Guests Online

A Login Script

[--Login Script--]
[--Level = Medium--]

Welcome to another one of my tutorials on scripting. This session is continuing from the registration script and you will
not understand most of the coding + im using most of the same database rows. First make a script called login.php and add this to it. This will be the login box.


<body bgcolor=#333333>
<form method="POST" action="logincheck.php">
<table width=50% bgcolor=#666666 border=1 bordercolor=black cellpadding=0 cellspacing=0 frame=box rules=all>
<font color=red><div align=center>USERNAME: <input style="background-color:#222222; font: 10pt verdana; color:#ffffff; border: 1px solid #555555;" type=text id="username" name="username" size="24">
PASSWORD: <input type="password" style="background-color:#222222; font: 10pt verdana; color:#ffffff; border: 1px solid #555555;" id=password name="password" size="24">
<input style="background-color:#CD8500; color:#000000; border: 1px solid #555555;" type="submit" name="Submit" value="Login"></div>
<a href=register.php>Register</a>
<div align="center">
Welcome To Your Site!

Now add this to the script, this is the php area of the code at the top.


$ud=mysql_num_rows(mysql_query("SELECT * FROM users"));

Now what you must do is add a row to your table `users` in your database called `ban`, make sure
it is 'enum' with the values '0','1' . Also add another row called 'online' and just make it
varchar100, no default value.

Now make another script named logincheck.php and insert this inside it.




header("Cache-control: private");

include 'includes/db_connect.php';

if ($_SESSION['username']){

echo "


window.location='logged_in.php'; /// When they are logged in already redirect them here.





if (!$_SESSION['username'] || !$_SESSION['email']){

$username = $_POST['username']; /// What the user put in the username box.

$password = $_POST['password']; /// What the user put in the password box.

$username = strip_tags($username);

$password = strip_tags($password);

$ip = $REMOTE_ADDR; /// The users IP address

$domain = $_SERVER['REMOTE_ADDR'];

$username=strtolower($username); /// Put the username in lower case letters.

if((!$username) || (!$password)){

echo "Please Enter All Necessary Fields.<br />"; /// If the username or
password are empty then echo this.


///check INFO

$sql = mysql_query("SELECT * FROM users WHERE username='$username' AND password='$password'");

/// This line above checks if there is anyone in the database with that username and password.

$login_check = mysql_num_rows($sql);

/// This checks how many people are on that database.

$ban = mysql_fetch_object($sql);

if ($ban->banned = "1"){
echo "This user has been banned, please contact admin via email to find out why.";

/// If the user is banned echo saying that he is banned and exit the session.



if ($login_check > '0'){

ini_set(session.cookie_lifetime, "3600");


$_SESSION['username'] = $username;


$_SESSION['email_address'] = $email_address;

/// security measures

$timestamp = time();

$timeout = $timestamp-$timeoutseconds;

$cool = gmdate('Y-m-d h:i:s');

mysql_query("UPDATE users SET online='$timestamp' WHERE username='$username'");

mysql_query("UPDATE users SET ip='$domain' WHERE username='$username'");


<meta http-equiv="Refresh" content=0;url="logged_in.php"> /// redirect them to the logged in page.


} else {

echo "Please Make Sure You Have Entered To Right Password/Username Combination. If You Have, Your Account May Not Be Activated<br />

<br />";

include 'login.php'; /// If their details are wrong echo the above and below that show login.php


Posted on Saturday 8th December 2007 at 11:22 AM
wheres th sql info?
Posted on Sunday 19th August 2007 at 11:47 AM
does it? i wasnt sure + this is new 1 :)
Posted on Saturday 18th August 2007 at 03:39 PM
Uhh.. The RMB usersystem allready has 'Login.php' so why make it again?