$_SESSION Problem????

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
vbora85
Forum Newbie
Posts: 1
Joined: Mon Nov 20, 2006 10:29 pm

$_SESSION Problem????

Post by vbora85 »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi all, I have problem with the $_SESSION variable.
Check this out:

temp1.php

Code: Select all

<?php
session_start();
funtion test1()
{
$_SESSION["temp"]="a";
//then direct to the file temp2.php
}

function test2()
{
$_SESSION["temp"]="b";
//then direct to file temp2.php
}
?>

temp2.php

Code: Select all

<?php
session_start();
echo $SESSION["temp"];
?>


In the process, I firstly call out the file temp1.php. Then within the function test1(), i direct to the file temp2.php. After finishing runing the file temp2.php, it continues its process in file temp1.php, runing function test2(). Again the function test2() also directs to the file temp2.php. Suprisingly, here is the result::::


bb


It should be like this:


ab



So, why the result is "bb"?? It should be "ab"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Any explaination!!!!!!!!!!!!!!!!


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

What's with all the exclamation marks?

Can you post the real code? What you've posted won't parse in PHP.
User avatar
ferreira.jorge
Forum Newbie
Posts: 11
Joined: Tue Nov 14, 2006 6:13 am
Location: Portugal

Post by ferreira.jorge »

Code: Select all

<?php
session_start();
echo $SESSION["temp"];
?>
You are trying to echo $_SESSION and you've got $SESSION.
Try change it.
Another thing is that test1() and test2() are functions and I can't see where you call them in your code.
Hope this helps...
Post Reply