Jump to content

[SOLVED] session variables not being transferred to new page


frijole

Recommended Posts

I am still working on my login script. I am trying to get the username of the person who signed to display on the front page that the form redirects to. I have a

<?php echo $_SESSION['userName']; ?>

on the front page. But, nothing is displayed. I can't tell why.

 

<?php

ob_start(); // buffer the output

require_once 'dbConnect.php';
require_once 'functions.php';

$error = '';


if ($_POST['logIn'] == 1) {	//if the form has been submitted

$userName = $_POST['user'];
$pass = $_POST['pass'];

$query = "SELECT * FROM users WHERE user_name='$userName' AND user_pass='$pass'";
$result = mysql_query($query) or die("connection error.");

if (empty($userName) || empty($pass)) {	//are any of the fields empty

	$error = "All fields must be filled out.";}

elseif (mysql_num_rows($result) != 1) { //if the username and password combo are not valid

	$error = "Invalid username, password combo.";}

else {	//log in was successful

	if (keepLogged ==1) {
		$year = 525600 + time();
		setcookie(thinksnack, 1, $year);	}

	$_SESSION['userName'] = $userName;
	$_SESSION['loggedIn'] = 1;
	header('Location: http://www.thinksnack.com/index.php');

	}
}

showLogInForm ($error);

ob_end_flush(); // dump the buffer

?>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.