Forum Moderators: coopster

Message Too Old, No Replies

Session variable overwriting problem

         

phparion

8:00 am on Aug 22, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hi,

i want to store a value in session array everytime page is called.

I am doing it like
PHP Code:
session_start();
$name = $_GET['name'];
$_SESSION[] = $name;

I am assuming that everytime page is loaded it will store name value automatically to the next index of session array, for example

PHP Code:
$_SESSION[0] = ist load
$_SESSION[1] = 2nd load
$_SESSION[2] = 3rd load

but it is overwriting the value at index 0 on every call like this,
PHP Code:
$_SESSION[0] = ist load //output array

$_SESSION[0] = 2nd load //output array

$_SESSION[0] = 3rd load //output array

and output array contains only one index 0 with the new value.

how can i store new values to next index of session array on every page call?

the_nerd

11:23 am on Aug 22, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'd use a whole array ($myvars) as a session variable. You'll then have to try if you have to use something like

$tmpvars = $_SESSION['myvars'];
$tmpvars[] = "next one, please";
....
$_SESSION['myvars']= $tmpvars

.. or if you can handle the array myvars directly. Not tested, just to give you an idea.

jatar_k

5:32 pm on Aug 22, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you could also count the vars in $_SESSION and then insert the next value

pixeltierra

4:55 am on Aug 23, 2006 (gmt 0)

10+ Year Member



array_push()

phparion

6:10 am on Aug 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



i found that i was using SESSION array as my own created array and that is not allowed so what i created an array within SESSION array and then access that array to accomplish my task and it is working now without any problem.

thanks for your replies.