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

?>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.