Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Session problem

Status
Not open for further replies.

sirugo

Programmer
Aug 1, 2000
162
SE
I'm trying to implement session on my site for the first time.
For security reasons I have register_globals turned OFF.

What happens is that the session variable don't seem to survive from one page to another. The value of the session variable resets.
For simplicity I have reduced the code but it still won't work - running on WinNT + PHP 4.2.3.

Page 1
******

<?

// Start session before all other headers!
session_start();

// displaying if it's set and it's value, before setting, shows 0 and 0
printf(&quot;isset: %d value: %d<BR>&quot;, isset($HTTP_SESSION_VARS['userid']), $HTTP_SESSION_VARS['userid'] );

// setting it
$HTTP_SESSION_VARS['userid'] = 2;

// displaying again - shows 1 and 2
printf(&quot;isset: %d value: %d<BR>&quot;, isset($HTTP_SESSION_VARS['userid']), $HTTP_SESSION_VARS['userid'] );

?>

<!-- Jumping to page 2 -->
<P><A HREF=&quot;sess2.php&quot;>Session 2</A>
</HTML>

Page 2
******

// Start session before all other headers!
session_start();

// displaying if it's set and it's value, shows 0 and 0 again...should be 1 and 2
printf(&quot;isset: %d value: %d<BR>&quot;, isset($HTTP_SESSION_VARS['userid']), $HTTP_SESSION_VARS['userid'] );

// setting it again
$HTTP_SESSION_VARS['userid'] = 3;

// // displaying again - shows 1 and 3, but dies again when I jump back
printf(&quot;isset: %d value: %d<BR>&quot;, isset($HTTP_SESSION_VARS['userid']), $HTTP_SESSION_VARS['userid'] );

?>

<!-- Jumping back -->
<P><A HREF=&quot;sess1.php&quot;>Session 1</A>
 
With register globals off, use $_session['var'] --
How can you be in two places at once when you're not anywhere at all?
 
I tried that too.
It gives me exactly the same output!

 
replace

session_start();

with

session_register( &quot;<variable name>&quot;);


i think it should work.
 
keos,
That would not make it work, quite the opposite, the session wouldn't be activated for that page.

iquela,
Do you get any errors? //Daniel
 
No errors!

Also I have tied the script with Opera on Windows. It worked perfectly!

But when I use any version of Explorer with my Mac it won't work. Yes, cookies are activated and many active cookies are already in the cookie-list.

So why do other sessions work but not this one?
IAnd why does it work on Opera/Windows but not Explorer/Mac?

Actually I have also tried the following script which is taken from the php.net manual on sessions:

<?php
session_start();
// Use $HTTP_SESSION_VARS with PHP 4.0.6 or less
if (!isset($_SESSION['count'])) {
$_SESSION['count'] = 0;
} else {
$_SESSION['count']++;
}
?>

Same problem!
 
i'm glad to see someone has the same problem that i do!! ;)

i'm using win2k pro, with IE 6.0, and I even have register_globals on, and it selectively remembers session variables. I'll declare and set two session variables in a function, but only one of them will be retained.

i also have this problem:
thread434-410976

=========================================================
if (!succeed) try();
-jeff
 
OK, I solved it.

hile I was poking around learing how to use sessions the &quot;secure way&quot; (without session_register etc), I altered one line in the php.ini by mistake:

session.cookie_path = ...should be
session.cookie_path = /
(no backslash!)

DON'T MESS WITH php.ini IF YOU'RE NOT 100% SURE WHAT YOU'RE DOING.

I spent eight hours on this one and the only problem was the slash... It's a personal record.

Hey jemminger!
What about showing us your code and I might help you out.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top