Page 1 of 1

session problem

Posted: Thu Nov 02, 2006 1:46 am
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();
	?>

Posted: Thu Nov 02, 2006 1:59 am
by aaronhall
You need to call session_start() before the $_SESSION superglobal becomes available.