473,586 Members | 2,491 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

$_SESSION problem - page reload creates new Session ID

Hello,

I am having trouble using the session vars in
PHP 4.3.9
OS: Win XP Prof
Web Server IIS (is local and there are no links to other servers from
the web pages I work on)
Browser: IE 6.0

The problem I am having is that each time I reload the same PHP page, I get
a different
Session ID (and thus all session vars are lost from one page to another).

let's say in firstpage.php I set
$_SESSION["firstvar"] = "someval";
$_SESSION["secvar"] = "otherval";

and in secpage.php I try to retrieve $_SESSION["firstvar"] , it gives me
"Undefined Index error"
I did not know what is happening and when printing out the session id (echo
SID;) I found out
that the ID is changing every time page is reloaded or when moving to
another page.

The problem is that I don't know what might reset the session since I use
"session_auto_s tart"
and have not played with session_start, session_destroy or anything else.

Can someone give me a hint on what might cause this ?

Thanks

Settings taken from PHP_INFO:
=============== =============== =============== =============
Session Support enabled
Registered save handlers files user

Directive Local Value Master Value
session.auto_st art On On
session.bug_com pat_42 On On
session.bug_com pat_warn On On
session.cache_e xpire 180 180
session.cache_l imiter nocache nocache
session.cookie_ domain no value no value
session.cookie_ lifetime 0 0
session.cookie_ path / /
session.cookie_ secure Off Off
session.entropy _file no value no value
session.entropy _length 0 0
session.gc_divi sor 100 100
session.gc_maxl ifetime 1440 1440
session.gc_prob ability 1 1
session.name PHPSESSID PHPSESSID
session.referer _check no value no value
session.save_ha ndler files files
session.save_pa th D:\PHP\SessionD ata D:\PHP\SessionD ata
session.seriali ze_handler php php
session.use_coo kies On On
session.use_onl y_cookies Off Off
session.use_tra ns_sid Off Off

Jul 17 '05 #1
13 23293
Mimi wrote:
Hello,

I am having trouble using the session vars in
PHP 4.3.9
OS: Win XP Prof
Web Server IIS (is local and there are no links to other servers from
the web pages I work on)
Browser: IE 6.0

The problem I am having is that each time I reload the same PHP page, I
get a different
Session ID (and thus all session vars are lost from one page to another).

let's say in firstpage.php I set
$_SESSION["firstvar"] = "someval";
$_SESSION["secvar"] = "otherval";

and in secpage.php I try to retrieve $_SESSION["firstvar"] , it gives me
"Undefined Index error"
I did not know what is happening and when printing out the session id
(echo SID;) I found out
that the ID is changing every time page is reloaded or when moving to
another page.

The problem is that I don't know what might reset the session since I use
"session_auto_s tart"
and have not played with session_start, session_destroy or anything else.

Can someone give me a hint on what might cause this ?

Thanks

Settings taken from PHP_INFO:
=============== =============== =============== =============
Session Support enabled
Registered save handlers files user

Directive Local Value Master Value
session.auto_st art On On
session.bug_com pat_42 On On
session.bug_com pat_warn On On
session.cache_e xpire 180 180
session.cache_l imiter nocache nocache
session.cookie_ domain no value no value
session.cookie_ lifetime 0 0
session.cookie_ path / /
session.cookie_ secure Off Off
session.entropy _file no value no value
session.entropy _length 0 0
session.gc_divi sor 100 100
session.gc_maxl ifetime 1440 1440
session.gc_prob ability 1 1
session.name PHPSESSID PHPSESSID
session.referer _check no value no value
session.save_ha ndler files files
session.save_pa th D:\PHP\SessionD ata D:\PHP\SessionD ata
session.seriali ze_handler php php
session.use_coo kies On On
session.use_onl y_cookies Off Off
session.use_tra ns_sid Off Off


Looks good to me.
Are you maybe jumping to another domain too when you say you jump to another
page?
Cookies are invisible when the domain changes (or even path in the same
domain in some cases)

http://www.domain1.com/somephp.php <- sets cookie with PHPSESSIONID

http://www.domain2.com/somephp.php <- invisible here

I am unsure if that is the case of course.

A great way to debug theese kind of problems is by simply investigating the
cookies set on your browser.
(Use Firefox or Mozilla for a userfriendly cookieviewer under tools)

Regards,
Erwin Moller
Jul 17 '05 #2
Mimi wrote:
The problem I am having is that each time I reload the same PHP page, I get
a different
Session ID (and thus all session vars are lost from one page to another).
<snip>
Can someone give me a hint on what might cause this ?


Did you start the session both for the firstpage.php and secpage.php?

--
Mail to my "From:" address is readable by all at http://www.dodgeit.com/
== ** ## !! ------------------------------------------------ !! ## ** ==
TEXT-ONLY mail to the whole "Reply-To:" address ("My Name" <my@address>)
may bypass my spam filter. If it does, I may reply from another address!
Jul 17 '05 #3
Pedro Graca wrote:
Mimi wrote:
The problem I am having is that each time I reload the same PHP page, I
get a different
Session ID (and thus all session vars are lost from one page to another).
<snip>
Can someone give me a hint on what might cause this ?


Did you start the session both for the firstpage.php and secpage.php?


Mimi wrote:
The problem is that I don't know what might reset the session since I use
"session_auto_s tart"


So that shouldn't be a problem.

Regards,
Erwin Moller
Jul 17 '05 #4
Mimi wrote (edited):
Can someone give me a hint on what might [make session not work] ? Settings taken from PHP_INFO: <snip> session.save_pa th D:\PHP\SessionD ata D:\PHP\SessionD ata


Are you sure PHP can write files here?

--
Mail to my "From:" address is readable by all at http://www.dodgeit.com/
== ** ## !! ------------------------------------------------ !! ## ** ==
TEXT-ONLY mail to the whole "Reply-To:" address ("My Name" <my@address>)
may bypass my spam filter. If it does, I may reply from another address!
Jul 17 '05 #5
Hello,

Thanks for all your input. Because there were several replies,
I will answer all of them here:

1) Yes, PHP can write in the "session_save_p ath" folder and I can see
there are 120 session files for the day and this is a local machine
where I am the only one to have access to.

2) The files I am trying to access are part of the same domain

3) Because I use "session_auto_s tart" in php.ini I am not required
to use "session_start( )" on php pages; So the answer is NO, I am not using
this function

Because the cause of the problem has not been identified, I am still
asking for your support.

Thanks
"Pedro Graca" <he****@dodgeit .com> wrote in message
news:sl******** ***********@ID-203069.user.uni-berlin.de...
Mimi wrote (edited):
Can someone give me a hint on what might [make session not work] ?

Settings taken from PHP_INFO:

<snip>
session.save_pa th D:\PHP\SessionD ata D:\PHP\SessionD ata


Are you sure PHP can write files here?

--
Mail to my "From:" address is readable by all at http://www.dodgeit.com/
== ** ## !! ------------------------------------------------ !! ## ** ==
TEXT-ONLY mail to the whole "Reply-To:" address ("My Name" <my@address>)
may bypass my spam filter. If it does, I may reply from another address!


Jul 17 '05 #6
Mimi wrote:
Because the cause of the problem has not been identified, I am still
asking for your support.


Do you have cookies enabled in your browser?
Verify that and also try passing the session id in the url:

---- firstpage.php ----
echo '<a href="secpage.p hp?', SID, '">second page</a>';
--
Mail to my "From:" address is readable by all at http://www.dodgeit.com/
== ** ## !! ------------------------------------------------ !! ## ** ==
TEXT-ONLY mail to the whole "Reply-To:" address ("My Name" <my@address>)
may bypass my spam filter. If it does, I may reply from another address!
Jul 17 '05 #7
Hello,

Yes, cookies and all the othe stuff are enabled on my browser (internet
options -> internet security).
And Yes, I use SID to display the session ID on my pages.

Since I am able to see the sessions created in "SessionDat a" folder and I
can see that the session vars
are there and set when the application is started. This page is displayed
properly.

The problem occurs when I click to go to another page and in this case at
"page load" a new session
is created which does not contain the session vars I set in the default
page.
A new session ID is created and therefore a new file can be found on the
"SessionDat a" folder.

The code I have in those pages is complex but I do not use any functions
that can trigger the app to
create a new session and that's why I do not understand what might cause
this behavior.

Is anybody aware, besides "session_start( )", of a known function or event
that may trigger
this problem ?

I understand that when cookies are not enabled this might happen but since
they can be set, something else
might happen.

Thank You again.

"Pedro Graca" <he****@dodgeit .com> wrote in message
news:sl******** ***********@ID-203069.user.uni-berlin.de...
Mimi wrote:
Because the cause of the problem has not been identified, I am still
asking for your support.


Do you have cookies enabled in your browser?
Verify that and also try passing the session id in the url:

---- firstpage.php ----
echo '<a href="secpage.p hp?', SID, '">second page</a>';
--
Mail to my "From:" address is readable by all at http://www.dodgeit.com/
== ** ## !! ------------------------------------------------ !! ## ** ==
TEXT-ONLY mail to the whole "Reply-To:" address ("My Name" <my@address>)
may bypass my spam filter. If it does, I may reply from another address!


Jul 17 '05 #8
Hello,

There is one thing I forgot to mention:

On my application I am using FRAMES, and I noticed one strange thing:

If I place the "include (SomeSessionVar s.php)" in the default FRAMESET page
(not in the Frame),
the session vars are not set. I have to include my file in the default page
of one of the
available frames. And only then the vars are set.
The files I talked about are in fact in the same directory ?!

"Mimi" <mi**@coco.co m> wrote in message
news:X1******** *****@fe39.usen etserver.com...
Hello,

Yes, cookies and all the othe stuff are enabled on my browser (internet
options -> internet security).
And Yes, I use SID to display the session ID on my pages.

Since I am able to see the sessions created in "SessionDat a" folder and I
can see that the session vars
are there and set when the application is started. This page is displayed
properly.

The problem occurs when I click to go to another page and in this case at
"page load" a new session
is created which does not contain the session vars I set in the default
page.
A new session ID is created and therefore a new file can be found on the
"SessionDat a" folder.

The code I have in those pages is complex but I do not use any functions
that can trigger the app to
create a new session and that's why I do not understand what might cause
this behavior.

Is anybody aware, besides "session_start( )", of a known function or event
that may trigger
this problem ?

I understand that when cookies are not enabled this might happen but since
they can be set, something else
might happen.

Thank You again.

"Pedro Graca" <he****@dodgeit .com> wrote in message
news:sl******** ***********@ID-203069.user.uni-berlin.de...
Mimi wrote:
Because the cause of the problem has not been identified, I am still
asking for your support.


Do you have cookies enabled in your browser?
Verify that and also try passing the session id in the url:

---- firstpage.php ----
echo '<a href="secpage.p hp?', SID, '">second page</a>';
--
Mail to my "From:" address is readable by all at http://www.dodgeit.com/
== ** ## !! ------------------------------------------------ !! ## ** ==
TEXT-ONLY mail to the whole "Reply-To:" address ("My Name" <my@address>)
may bypass my spam filter. If it does, I may reply from another address!




Jul 17 '05 #9
Mimi wrote:
There is one thing I forgot to mention:

On my application I am using FRAMES, and I noticed one strange thing:


Frames shouldn't be a problem (as far as session data is concerned --
frames are bad!).

A simple script with sessions works for you with your current
configuration?
========
<?php
session_start() ;
if (!isset($_SESSI ON['hits'])) $_SESSION['hits'] = 0;
++$_SESSION['hits'];

echo '<p>Session hits: ', $_SESSION['hits'], '</p>';
echo '<p>Refresh the page or click <a href="', $_SERVER['PHP_SELF'],
'">here</a>.';
?>
--------
At every refresh this page /should/ keep increasing the displayed number
of hits. Does it?

--
Mail to my "From:" address is readable by all at http://www.dodgeit.com/
== ** ## !! ------------------------------------------------ !! ## ** ==
TEXT-ONLY mail to the whole "Reply-To:" address ("My Name" <my@address>)
may bypass my spam filter. If it does, I may reply from another address!
Jul 17 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
8397
by: Dynamo | last post by:
Yep its me again, I have succesfully created a login page for my site. I have used the PHP_SELF so that once the user has succesfully logged on the page reloads. Everything works fine the first time somebody tries to log in but when they revisit, the log on page is bypassed and it goes straight to the information page. I have a sneaky...
8
3368
by: DKM | last post by:
Here are the source code files to a Java applet that utilizes LiveConnect to communicate with Javascript, and the HTML file. The thing works both in IE 6.0 and FireFox 1.4. but with some problems. IE crashes when one refreshes the page or leave the page. This happens only after calling the Java method more than once. It does not crash if...
3
4541
by: Carpe Diem | last post by:
Hello I have an aspx page that loses Session("user") value after a few minutes even after I set <sessionState mode="InProc" cookieless="false" timeout="300"> in web.config and wrote function Session_Start() { Session.Timeout = 3000; } in global.asax
3
5692
by: michael | last post by:
Good Morning Everyone, I am writing a script to add and remove rows from a table. Here are the two functions: function newRow(rowNo) { var theTable = document.getElementById("table1"); var newRow = theTable.insertRow(rowNo);
2
1434
by: Brenden Bixler | last post by:
Hello. I've got a long web form that has to reload 6-7 times to validate data (sigh, I know) making for a rocky-enough experience for users. To add insult to injury, each time the page reloads, it loads and scrolls back to the top instead of remaining in the section that caused the page to reload. I'm looking for a way to ensure that when a...
1
3404
by: ijevsk | last post by:
I have asp page of my system and when I click on the link I want to open new login page.If I enter to the system throuth this page my old session is overides. I wont that to have two pages with different session and cookies. how can i do that in asp and asp.net
2
2155
by: ramanaths | last post by:
Hi I have a page that shows many thumbnail images. on load of this page i have some code that invokes a javascript which shows a message saying 'loading images'... this is hidden once all the page/images loads fully. when i navigate to some other page and then hit the back button of the browser the javascript fires and i get the 'loading...
1
3400
by: pendem | last post by:
I mean can set a variable value in a script to be unchanged even after page reload? for example if i set a value of a global variable "val" to 2 ; so using onbeforeunload() or onunload(), i will change the value of variable "val" to 5; so can i in anyway get the value of variable "val" equal to 5? after loading the page..,i mean after onload()...
0
1242
by: tangara | last post by:
Hi, I would like to know how to make use of session to apply in my jsp pages. My login.html page contains the session codes as follows:- <%@page import="java.util.*"%> <String str = request.getParameter("UserID"));
0
7841
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8204
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7965
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8220
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6617
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5712
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5392
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3838
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1452
muto222
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.