Solved

Help with Login Page

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

809 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