Solved

Help with Login Page

Posted on 2006-11-11
5
198 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

707 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

12 Experts available now in Live!

Get 1:1 Help Now