Jump to content

Session variables not holding from page to page


Bigfunkychief

Recommended Posts

This is starting to drive me crazy...tried scouring the Internet and forums but can't figure it out.

 

I have an existing website on this Apache webserver that is passing Session Variables just fine...

 

I am creating a new site, and copied the basic framework from the existing site but for some reason session variables aren't being passed.

 

My code for home.php (where it registers the vars) is this:

 

-----{snip}

 

<?php

session_start();

header("Cache-control: private");

 

$userlogin = $_GET['userlogin'];

 

// REGISTER SESSION VARIABLES FOR USER

// ------------------------------------------------

 

$_SESSION['userlogin'] = $userlogin;

$_SESSION['firstname'] = $firstname;

$_SESSION['lastname'] = $lastname;

$_SESSION['emailaddr'] = $emailaddr;

 

 

echo 'User login session var is ' . $_SESSION['userlogin'];

echo '<br><a href="page1.php">Click here to see what happens</a>';

exit();

 

 

-----{snip}

 

 

And, my page1.php code is this:

 

-----{snip}

 

<?php

session_start();

header("Cache-control: private");

 

echo "Session is: ";

echo $_SESSION['userlogin'];

exit;

 

?>

-----{snip}

 

 

Home.php shows the following output:

 

User login session var is srace

Click here to see what happens

 

Page1.php shows the following output:

Session is:

 

 

 

 

Any help is appreciated! I'm 2 days into trying to figure this out and driving me nuts! Thanks!!

Ah ha.  Here's what I get on the first page (home.php):

 

----{snip}

Warning: session_start() [function.session-start]: The session id contains illegal characters, valid characters are a-z, A-Z, 0-9 and '-,' in /var/www/proposals/home.php on line 5

 

Notice: Undefined variable: firstname in /var/www/proposals/home.php on line 14

 

Notice: Undefined variable: lastname in /var/www/proposals/home.php on line 15

 

Notice: Undefined variable: emailaddr in /var/www/proposals/home.php on line 16

User login session var is srace

Click here to see what happens

Warning: Unknown: The session id contains illegal characters, valid characters are a-z, A-Z, 0-9 and '-,' in Unknown on line 0

 

Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/var/lib/php/session) in Unknown on line 0

----{snip}

 

 

Second page (page1.php):

 

----{snip}

Warning: session_start() [function.session-start]: The session id contains illegal characters, valid characters are a-z, A-Z, 0-9 and '-,' in /var/www/proposals/page1.php on line 5

Session is:

Notice: Undefined index: userlogin in /var/www/proposals/page1.php on line 9

 

Warning: Unknown: The session id contains illegal characters, valid characters are a-z, A-Z, 0-9 and '-,' in Unknown on line 0

 

Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/var/lib/php/session) in Unknown on line 0

----{snip}

 

Thanks for the tip to turn on the error message. Much easier to tshoot!!

 

After researching the error about invalid chars in the session id, I found someone recommending this fix:

 

session_name("sess_SomethingSecure");

session_start();

 

Adding the session_name before the start has seemed to fix my problem.  I'm happy to leave it like this, but does anyone know if doing this is any type of security issue or sloppy code? 

 

Thanks again for the help.

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.