|
Another Question; This Time about Logging in and Register.
|
|
Topic Started: Feb 23 2005, 12:25 PM (335 Views)
|
|
Dennis
|
Feb 23 2005, 12:25 PM
Post #1
|
- Posts:
- 7,431
- Group:
- Members
- Member
- #16,894
- Joined:
- April 17, 2004
- I'm Browsing With
- Chrome
|
Well, Im trying to make a log in script, and It's not working. I'd post it if it's needed, but it covers about 6 files, so It'd be a bit big. For now, I'm just going to post a couple of them.
- login.php
-
<?php /* +---------------------------------------------------------------------------------------------------------------------- | Script Created By Dennis Pedrie of BoredBoards.com | Copyright, 2005. All rights reserved. May not be reproduced in whole or part. +---------------------------------------------------------------------------------------------------------------------- | Login.php Script for Compassion Pregnancy Center's Client ID Tracking System | Started February 15, 2005. | Dedicated to Christa. You rock! +---------------------------------------------------------------------------------------------------------------------- */
// database connect script.
require 'compassion_config.php';
if($logged_in == 1) { die('You are already logged in, '.$_SESSION['username'].'.');
}
?> <html> <head> <title>Login</title> </head> <body> <?php
if (isset($_POST['submit'])) { // if form has been submitted
/* check they filled in what they were supposed to and authenticate */ if(!$_POST['uname'] | !$_POST['passwd']) { die('You did not fill in a required field.'); }
// authenticate.
if (!get_magic_quotes_gpc()) { $_POST['uname'] = addslashes($_POST['uname']); }
$check = $db_object->query("SELECT username, password FROM users WHERE username = '".$_POST['uname']."'");
if (DB::isError($check) || $check->numRows() == 0) { die('That username does not exist in our database.'); }
$info = $check->fetchRow();
// check passwords match
$_POST['passwd'] = stripslashes($_POST['passwd']); $info['password'] = stripslashes($info['password']); $_POST['passwd'] = md5($_POST['passwd']);
if ($_POST['passwd'] != $info['password']) { die('Incorrect password, please try again.'); }
// if we get here username and password are correct, //register session variables and set last login time.
$date = date('m d, Y');
$update_login = $db_object->query("UPDATE users SET last_login = '$date' WHERE username = '".$_POST['uname']."'");
$_POST['uname'] = stripslashes($_POST['uname']); $_SESSION['username'] = $_POST['uname']; $_SESSION['password'] = $_POST['passwd']; $db_object->disconnect(); ?>
<h1>Logged in</h1> <p>Welcome back <?php echo $_SESSION['username']; ?>, you are logged in.</p>
<?php
} else { // if form hasn't been submitted
?> <h1>Login</h1> <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post"> <table align="center" border="1" cellspacing="0" cellpadding="3"> <tr><td>Username:</td><td> <input type="text" name="uname" maxlength="40"> </td></tr> <tr><td>Password:</td><td> <input type="password" name="passwd" maxlength="50"> </td></tr> <tr><td colspan="2" align="right"> <input type="submit" name="submit" value="Login"> </td></tr> </table> </form> <?php } ?>
- check_login.php
-
<?php
/* check login script, included in db_connect.php. */
session_start();
if (!isset($_SESSION['username']) || !isset($_SESSION['password'])) { $logged_in = 0; return; } else {
// remember, $_SESSION['password'] will be encrypted.
if(!get_magic_quotes_gpc()) { $_SESSION['username'] = addslashes($_SESSION['username']); }
// addslashes to session username before using in a query. $pass = $db_object->query("SELECT password FROM users WHERE username = '".$_SESSION['username']."'");
if(DB::isError($pass) || $pass->numRows() != 1) { $logged_in = 0; unset($_SESSION['username']); unset($_SESSION['password']); // kill incorrect session variables. }
$db_pass = $pass->fetchRow();
// now we have encrypted pass from DB in //$db_pass['password'], stripslashes() just incase:
$db_pass['password'] = stripslashes($db_pass['password']); $_SESSION['password'] = stripslashes($_SESSION['password']);
//compare:
if($_SESSION['password'] == $db_pass['password']) { // valid password for username $logged_in = 1; // they have correct info // in session variables. } else { $logged_in = 0; unset($_SESSION['username']); unset($_SESSION['password']); // kill incorrect session variables. } }
// clean up unset($db_pass['password']);
$_SESSION['username'] = stripslashes($_SESSION['username']);
?>
If you need any more, there is a config file, a db_connect file and a register file. :/
|
|
|
| |
|
Seth
|
Feb 23 2005, 12:48 PM
Post #2
|
- Posts:
- 18,984
- Group:
- Members
- Member
- #100
- Joined:
- November 17, 2002
|
What's it doing? :rolleyes:
|
|
|
| |
|
SargeTron
|
Feb 23 2005, 12:49 PM
Post #3
|
|
Unregistered
|
Le email me teh files
sargetron at knd.org.uk
|
|
|
| |
|
Dennis
|
Feb 23 2005, 12:51 PM
Post #4
|
- Posts:
- 7,431
- Group:
- Members
- Member
- #16,894
- Joined:
- April 17, 2004
- I'm Browsing With
- Chrome
|
@Seth. It's supposed to be a login program.
@Sargetron. Check your E-Mail in a couple minutes.
|
|
|
| |
|
SargeTron
|
Feb 23 2005, 12:57 PM
Post #5
|
|
Unregistered
|
Ok dude, I'd be happy to help as I'm a veteran to professional in PHP.
|
|
|
| |
|
SkItZo
|
Feb 23 2005, 07:41 PM
Post #6
|
- Posts:
- 484
- Group:
- Members
- Member
- #2,705
- Joined:
- June 23, 2003
|
What are the errors you recieve?
|
|
|
| |
|
Dennis
|
Feb 23 2005, 09:07 PM
Post #7
|
- Posts:
- 7,431
- Group:
- Members
- Member
- #16,894
- Joined:
- April 17, 2004
- I'm Browsing With
- Chrome
|
I'm not getting any errors, it's just not logging in.
|
|
|
| |
|
Seth
|
Feb 23 2005, 09:10 PM
Post #8
|
- Posts:
- 18,984
- Group:
- Members
- Member
- #100
- Joined:
- November 17, 2002
|
- The Balrog
- February 23, 2005 07:07 PM
I'm not getting any errors, it's just not logging in.
^-- that's what I wanted to know.
|
|
|
| |
|
Seth
|
Feb 23 2005, 09:11 PM
Post #9
|
- Posts:
- 18,984
- Group:
- Members
- Member
- #100
- Joined:
- November 17, 2002
|
- SargeTron
- February 23, 2005 10:57 AM
Ok dude, I'd be happy to help as I'm a veteran to professional in PHP.
He won't be helping anytime soon as he's "gone" for a couple weeks :rolleyes:
|
|
|
| |
| 1 user reading this topic (1 Guest and 0 Anonymous)
|