473,480 Members | 2,325 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

PHP session variable problem

2 New Member
Hello,

I am using PHP 5, Apache on WinXP.

Here is the first php named 1.php

<?php
session_start();
$_SESSION[0] = 22 ;
echo $_SESSION[0];
?>
<a href="http://localhost/2.php"> 2php </a>

Here is second php named 2.php
<?php
session_start();
if (isset( $_SESSION[0]))
{echo 'set';}
else
{echo 'not set';}
?>

When I ran http://localhost/1.php, there was no problem at all. When I click on the link, 2.php gives 'not set'. Why is the session variable $_SESSION[0] not passed on for 1.php to 2.php? Please help.
Dec 5 '07 #1
3 2908
arunj82
15 New Member
Hi,
Dont use 0 inside $_SESSION['']. I think '0' or '1' indicates true or false. This might be the problem. Instead of 0 I used the variable value inside session, now it is displaying the set.


This code works.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. session_start();
  3. $_SESSION["value"] = "Tested" ;
  4. echo "Session value is ".$_SESSION["value"];
  5. echo "<BR>";
  6. ?>
  7. <a href="http://localhost/two.php"> Two.php</a>
  8.  
  9.  
  10. <?php
  11. session_start();
  12. if (isset( $_SESSION["value"]))
  13. {echo 'set';}
  14. else
  15. {echo 'not set';}
  16. ?>
Dec 6 '07 #2
maingroup
2 New Member
Hi,

Thanks for you help. It still does not work on my system.

I looked into Cookies in the browser (I use Firefox). Under localhost, it shows localhost PHPSESSID. Session variable of $_SESSION["value"] isn't there. I thought all session variables are stored as cookies along with the session id until the session is destroied.


By the way, session variable is essentially an array. I believe the syntax of $_SESSION[0] is perfectly legitimate.

Thanks
Dec 6 '07 #3
clai83
41 New Member
Hi,

Thanks for you help. It still does not work on my system.

I looked into Cookies in the browser (I use Firefox). Under localhost, it shows localhost PHPSESSID. Session variable of $_SESSION["value"] isn't there. I thought all session variables are stored as cookies along with the session id until the session is destroied.


By the way, session variable is essentially an array. I believe the syntax of $_SESSION[0] is perfectly legitimate.

Thanks
You mentioned that session variables are stored as "cookies along with the session id", however, that is not true in your case. The method that you are using I believe would not store the variables in the cookie, rather it would store it in a session file on the server side. The cookie is just to tell the server, which session it should be looking for.

Here is an example.

[PHP]
<?php
session_start();
$_SESSION['one'] = 1;
$_SESSION['two'] = 2;
echo session_id();
?>
[/PHP]

now if I were to go to my C:/wamp/www/tmp/ [whatever my session id was] file

and open it in a text editor.

one|i:1;two|i:2;

The above is stored in that file. There is documentation on session on www.php.net .


Anyhow, I tried your code, and I also tried putting in numbers like $_SESSION[3] , $_SESSION[4] and so on. They all give the same effect. I'm not an expert, but I think the above post might be right about using numbers are your keys in a superglobal.
Dec 7 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
6241
by: Nick Whitelegg | last post by:
Hello, I'm having an odd problem with combining an authentication session variable with header() redirection. Basically I have an authentication script which checks a username/password. If the...
11
3318
by: doltharz | last post by:
Please Help me i'm doing something i though was to be REALLY EASY but it drives me crazy The complete code is at the end of the email (i mean newsgroup article), i always use Option...
1
2009
by: Scott Wickham | last post by:
I'm having a problem saving session information on one form and retrieving it on a subsequent form...for only one out of a number of users. Actually, I'm not absolutely certain it's a session...
1
1886
by: farooqazeem | last post by:
Hi guys, I’m facing some problem can u solve it. Problem is: I’m giving user Id and password in (Login_sess.asp) and submit it to page (sess_test.asp). I am setting session variable...
5
4120
by: Marc Rivait | last post by:
Here is a very interesting scenario. I have a simple test application that loads a page and sets a session variable on the load event. On the first page there is a link to a second page. The...
9
2434
by: William LaMartin | last post by:
I have a problem, mentioned here before, of Session and Application variables disappearing at one site but not at others or on my development computer. The problem is illustrated by an example...
9
2363
by: Greg Linwood | last post by:
I'm having difficulty understanding Session state in ASP.Net. It's almost embarrassing asking this as I've been using ASP since it was first released & it really shouldn't be this hard to use -...
1
737
by: Werner | last post by:
Hi Patrick! Can you give an example of how to use a frameset inside an aspx-file? When I create a new frameset in Visual Studio.Net it just gives me a htm-File. Or give me a link where I can...
7
2227
by: Lucas Tam | last post by:
I'm calling the session object from an inherited page. The page is based off an herited class which outputs XML. Does anyone know why the session object would be nothing? ...
4
1938
by: T Ralya | last post by:
I am told that ASP.NET controls the session ID and session variables, but that does not fit my symptoms. I am posting here as directed. I'm hoping that someone can at least recommend something to...
0
7051
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6915
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7054
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7097
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
6993
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4493
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3003
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1307
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
567
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.