Welcome to WebmasterWorld Guest from 54.163.35.238

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

$ SESSION troubles

     

Pico_Train

11:50 am on Dec 29, 2008 (gmt 0)

10+ Year Member



I am using $_SESSION to store a few details when a page loads. I refresh this page every 2 minutes and the $_SESSION variables get re-used without causing the whole to crash because on refresh you lose all the post data.

Now if the user wants to go back and add something, and then continue on to the page where the $_SESSION gets created and stored, the $_SESSION stays the same as the old one and the new addition is nowhere to be found.

Is there a way I can re-create or update a session?

My first check does -
if(!empty($_POST) && !isset($_SESSION))
{
set a whole bunch of $_SESSION vars with session_register('varname');
}else{

session_start();
$_SESSION['var'] = $_SESSION['var'];

}

even if close the browser, say an old session had 3 items and I go and do one with 1 item, when I print_r($_SESSION); it will have 3 instead of 1...

Getting a bit frustrated here and would really appreciate any help anyone can provide. Thanks!

Habtom

12:02 pm on Dec 29, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



...the problem is in this part of the code:

if(!empty($_POST) && !isset($_SESSION))

It is set once, so the second time it just goes to the else.

You probably don't need to see if the session is set, so the following line

if(!empty($_POST))
would be sufficient.

Habtom

12:13 pm on Dec 29, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



...and btw session_register is long deprecated now, you can use something similar to $_SESSION['anything'] = $_POST['something']; to create a session.

Pico_Train

12:21 pm on Dec 29, 2008 (gmt 0)

10+ Year Member



yeah I know about the session_register bit but my server is not on 5.3 or above so will get rid of that once the server is upgraded.

Thanks for your help, still working on it!

amznVibe

12:22 pm on Dec 29, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Um, you are doing a session_start, right?
[us3.php.net...]

Habtom

12:30 pm on Dec 29, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Use of $_SESSION is preferred, as of PHP 4.1.0

[php.net...]
If your script uses session_register(), it will not work in environments where the PHP directive register_globals is disabled.

As of PHP 4.2.0, the default value for the PHP directive register_globals is off . . . The PHP community discourages developers from relying on this directive, and encourages the use of other means, such as the superglobals.

Pico_Train

12:34 pm on Dec 29, 2008 (gmt 0)

10+ Year Member



gotcha, have removed them, see how that works in a bit but first to fix this $_SESSION issue. Driving me up the wall!

Pico_Train

12:43 pm on Dec 29, 2008 (gmt 0)

10+ Year Member



Got it! Thanks guys! Removed all session_registers and all seems well.

Great stuff!

 

Featured Threads

Hot Threads This Week

Hot Threads This Month