Solved

Help with Login Page

Posted on 2006-11-11
5
199 Views
Last Modified: 2006-11-18
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>
<?
}
?>
0
Comment
Question by:aumandg
  • 3
  • 2
5 Comments
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 17921676
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
0
 

Author Comment

by:aumandg
ID: 17923606
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.
0
 
LVL 54

Accepted Solution

by:
b0lsc0tt earned 500 total points
ID: 17926299
I don't have a specific script to recommend to you for that.  Another expert may have one though.  I have found one PHP question that does have a script and some good information at http:Q_21182871.html.  There are a number of pre-made scripts at http://www.hotscripts.com/PHP/Scripts_and_Programs/User_Authentication/.  I hope that one of these helps otherwise let us know here and we may be able to find or come up with something else.

bol
0
 

Author Comment

by:aumandg
ID: 17929883
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!
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 17931138
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
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now