PHP Session Problems

software development

#1

Hi there, I am not able to succesfully maintain a PHP session. I’m using the standard PHP 4.x dreamhost version of PHP (I have not customized it at all).

My login page includes the following code once login is succesful:

session_start();
$_SESSION[‘userid’] = $userid;

The next page I post to tries to get a value from the session array and cannot find it. Can anyone help? Its putting a big hamper on my development. I searched the wiki but didn’t come across the answer yet.

Thanks!


#2

What version of PHP are you using? PHP4 and PHP5 on Dreamhost have register_globals set differently - which makes a difference on how you pass variables. :wink:

–rlparker


#3

Thanks for the reply, I’m using PHP 4.


#4

Doh! I’m sorry! You very clearly stated that in your original post - I just “brainfarted” :open_mouth: .

I don’t have another suggestion at present; but I’ll “dwell on it” a bit and post back if I have anything constructive. ( rlparker retreats to a corner to take a remedial reading course :wink: )

–rlparker


#5

not sure whether this helps or not.

in the next page, you should start session before html header

<?php session_start(); ?>

in the body, try to retrieve the session.

Save [color=#CC0000]$97[/color] (max discount) on dreamhost by using promo code: [color=#CC0000]97CRAZY[/color].


#6

That’s the ticket; “session_start():” needs to be called pretty much at the beginning (before any other output) of any PHP script that makes use of session variables.


#7

If there is anything, such as blank lines before <?php, that will get in the way of starting a session. All headers, including those to support sessions must be sent before the page content. Anything in a php file that is not within <?php … > is content.

A simple blank line at the start of the file will prevent the headers that need to be sent to support a session.