Page 1 of 1

$_SESSION troubles!!!

Posted: Thu Sep 22, 2005 9:40 pm
by snx
trying to learn more about session variables and i keep running into a wall..
consider this:

POST variable 'info' which is a string of a filename slashes replaced by underscores

try to insert into the SESSION array using something like

$_SESSION [$info] = $info;

but everytime i do another POST and print_r the SESSION, the last data has been replaced by the new data even though they are entirely different???? arghh!!!

i have tried to push the SESSION array, it doesnt seem to work but its as if it is recreating the array allover each time... help!!!

&thanks!!!
jon.

Posted: Thu Sep 22, 2005 9:53 pm
by neophyte
try:

Code: Select all

$_SESSION['info'] = $info;

Posted: Thu Sep 22, 2005 10:02 pm
by snx
but what if i am stockpiling data i need to use a variable that is at least incremental????

thx
jonathan

Posted: Thu Sep 22, 2005 10:25 pm
by feyd
you can store arrays into any variable... including session ones ;)

still confused about $_SESSION variable

Posted: Fri Sep 23, 2005 3:41 pm
by snx
Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


try this:

Code: Select all

<?php
session_start();
header("Cache-control: private"); //IE 6 Fix

$word=$_POST['word'];
array_push($_SESSION, $word);
print_r ($_SESSION);
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>I'm Gonna Snap</title>
</head>

<body>
<br />
<br />
<br />
<FORM METHOD="POST" ACTION="thisone.php">
Word: <input type="text" name="word">
<input type="SUBMIT" value="Submit">
</FORM>
</body>
</html>
instead of adding to the array, it will replace it everytime... why is this? and whats the resolution?

whattupwitdat???
j.


Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Fri Sep 23, 2005 3:57 pm
by feyd
$_SESSION cannot be worked with like a numeric array. It must be used as an associative array.

sheesh

Posted: Fri Sep 23, 2005 5:17 pm
by snx
Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


i swear i was trying the assiciative styles originally and it didnt work... 

heres the modified code for noobs like me:

Code: Select all

<?php
session_start();
header("Cache-control: private"); //IE 6 Fix

$word=$_POST['word'];
$_SESSION[$word] = $word;

print_r ($_SESSION);
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>I'm Gonna Lose It</title>
</head>

<body>
<br />
<br />
<br />
<FORM METHOD="POST" ACTION="thisone.php">
Word: <input type="text" name="word">
<input type="SUBMIT" value="Submit">
</FORM>
</body>
</html>
thanks f.


Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Fri Sep 23, 2005 5:48 pm
by pilau
What's this:

Code: Select all

header("Cache-control: private"); //IE 6 Fix
IE fix? A fix for what?

Posted: Fri Sep 23, 2005 6:19 pm
by feyd
IE doesn't really like playing correctly with sessions and some other things at times.. it's the brute force fix for it..