session problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kristie380
Forum Commoner
Posts: 36
Joined: Sun Oct 09, 2005 10:51 pm

session problem

Post by kristie380 »

My Session Script for my user login is not returning any information. Here is my script:

Code: Select all

<?php

// database connect script.

require 'db_connect.php';

if($logged_in == 1) {
	die('You are already logged in, '.$_SESSION['email'].'.');

}


?>
<?php


	/* check they filled in what they were supposed to and authenticate */
	if ((!$_POST['email']) || (!$_POST['password'])) {
		die('You did not fill in a required field.');
	}

	// authenticate.

	if (!get_magic_quotes_gpc()) {
		$_POST['email'] = addslashes($_POST['email']);
	}

	$check = $db_object->query("SELECT * FROM `signup` WHERE `email` = '$_POST[email]'");

	if (DB::isError($check) || $check->numRows() == 0) {
		die('That email does not exist in our database.');
	}

	$info = $check->fetchRow();

	// check passwords match

	$_POST['password'] = stripslashes($_POST['password']);
	$info['password'] = stripslashes($info['password']);
	$_POST['password'] = md5($_POST['password']);

	if ($_POST['password'] != $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 `signup` SET `last_login` = \"$date\",  WHERE `email` = '$_POST[email]'");

	$_POST['email'] = stripslashes($_POST['email']);
	$_SESSION['email'] = $_POST['email'];
	$_SESSION['password'] = $_POST['password'];
	$db_object->disconnect();
	?>
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

You need to call session_start() before the $_SESSION superglobal becomes available.
Post Reply