$_SESSION troubles!!!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
snx
Forum Newbie
Posts: 9
Joined: Wed Aug 31, 2005 6:15 pm

$_SESSION troubles!!!

Post 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.
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post by neophyte »

try:

Code: Select all

$_SESSION['info'] = $info;
snx
Forum Newbie
Posts: 9
Joined: Wed Aug 31, 2005 6:15 pm

Post by snx »

but what if i am stockpiling data i need to use a variable that is at least incremental????

thx
jonathan
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you can store arrays into any variable... including session ones ;)
snx
Forum Newbie
Posts: 9
Joined: Wed Aug 31, 2005 6:15 pm

still confused about $_SESSION variable

Post 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]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

$_SESSION cannot be worked with like a numeric array. It must be used as an associative array.
snx
Forum Newbie
Posts: 9
Joined: Wed Aug 31, 2005 6:15 pm

sheesh

Post 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]
pilau
Forum Regular
Posts: 594
Joined: Sat Jul 09, 2005 10:22 am
Location: Israel

Post by pilau »

What's this:

Code: Select all

header("Cache-control: private"); //IE 6 Fix
IE fix? A fix for what?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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..
Post Reply