Link to home
Start Free TrialLog in
Avatar of aumandg
aumandgFlag for United States of America

asked on

Help with Login Page

I found this login code at php noise and wanted to use it but I do not understand where it gets any info from mysql to verify login at......

Need help understanding it.  I found this at http://www.phpnoise.com/tutorials/26/1

here is the code--->

<?php
// valid login credentials
$username = 'admin';  
$password = 'admin_pass';
// grab current time
$time=time();  

// handle the logout event
if ($logout == true) {    
 setcookie ("user", md5($_POST[user]), $time-3200);  
 setcookie ("pass", md5($_POST[pass]), $time-3200);  
 header("Location: logintest.php");
}

// handle validation event
if ($_POST[user] && $_POST[pass]) {    
 if ($_POST[user]==$username && $_POST[pass]==$password)
 {
  setcookie ("user", md5($_POST[user]), $time+3200);  
  setcookie ("pass", md5($_POST[pass]), $time+3200);  
  header("Location: logintest.php");
 } else { $login_error= true; }
}
 
// handle login event, both successful and erroneous, or show login screen  
if ($login_error == true) { ?>
 <table align=center style="font-family:arial; font-size:12; border:1 solid #000000;">
  <tr><td align=center bgcolor=#BAC7D8>LOGIN ERROR</td></tr>
  <tr><td align=center><b>Invalid Username and/or Password</b><br><br>
      <a href=logintest.php>Back</a></td></tr>
 </table>
<?
} elseif ($_COOKIE[user] == md5($username) && $_COOKIE[pass] == md5($password)) { ?>
 <table align=center style="font-family:arial; font-size:12; border:1 solid #000000;">
  <tr><td align=center bgcolor=#BAC7D8>SECURE AREA</td></tr>
  <tr><td align=right><a href=logintest.php?logout=true>Logout</a></td></tr>
  <tr><td>You have successfully logged in.<br><br>
   Encrypted Username: <b><?=  $_COOKIE[user] ?></b><br>
   Encrypted Password: <b><?= $_COOKIE[pass] ?></b><br>
  </td></tr>
 </table>
<?
} else {  
?>
<form action=logintest.php method=post>
 <table align=center style="font-family:arial; font-size:12; border:1 solid #000000;">
  <tr><td colspan=2 align=center bgcolor=#BAC7D8>LOGIN</td></tr>
  <tr><td align=right>Username: </td><td><input type=text name=user size=15></td></tr>
  <tr><td align=right>Password: </td><td><input type=password name=pass size=15></td></tr>
  <tr><td align=center colspan=2><input type=submit value=Login></td></tr>
 </table>
</form>
<?
}
?>
Avatar of b0lsc0tt
b0lsc0tt
Flag of United States of America image

aumandg,

This code doesn't check the user name and password against a database.  It only supports one user name and password and they are written write in the code.  The lines below set the user name as admin and the password as admin_pass.  You can change each variables value to the one you want.

$username = 'admin';  
$password = 'admin_pass';

It will take some relatively major changes to this code to have it work with a database and support individualized logins.

Let me know if you have any questions or need more information.

b0lsc0tt
Avatar of aumandg

ASKER

Ah, ok....

I am looking for a login that will check the data base for usser and password with a time out and log out.  Do you know of any code on line.  I have done a search here but have not found anything that I understand, that is simple.
ASKER CERTIFIED SOLUTION
Avatar of b0lsc0tt
b0lsc0tt
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of aumandg

ASKER

bol,

I found a great login script at hotscripts.com!  Super easy and a no brainer for anyone.....

Thank you for the hotscripts website forgot all about that place!

The script that I am using is here

http://www.mpdolan.com/login_redirect.htm

I RECOMMEND THIS TO ALL!  CAN NOT SAY HOW MUCH TIME THIS WILL SAVE YOU!
Great!  Good choice to go for a pre-made script.  I'm glad I could help.  Thank you for the grade, the points and the fun question.

bol