session handling

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
jai_lamba
Forum Newbie
Posts: 2
Joined: Thu Jul 18, 2002 4:53 am

session handling

Post by jai_lamba »

hi
I am trying to execute this code but this is not functioning. This always return 0. I dont want to use session_register().


<?php
if (isset($HTTP_SESSION_VARS['count'])) {
$HTTP_SESSION_VARS['count']++;
}
else {
$HTTP_SESSION_VARS['count'] = 0;
}
?>
Thanks
Jai
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

You really should have added this to the bottom of your previous post - there is no need to start a new topic.

In order to use sessions you must have session_start() at the top of any scripts that set session variables or try to use them.

Mac
Buggy007
Forum Newbie
Posts: 4
Joined: Thu Jun 27, 2002 9:26 am

but now it's me who is having a question...

Post by Buggy007 »

I'm registering on my first page session variables:

$_SESSION["strTest"] = "hello";

This works, but when I try to access the variables on the next page, it doesn't, though I have put

session_start();

on top of the code. I can register new variables, but

$_SESSION["strTest"]

is not known.
What can be wrong? Is there something missing? I checked several examples, but it seems to be the same - only one difference: the others work... :(
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

What version of PHP are you using? $_SESSION won't work as expected (it'll just be a normal array) in versions less than 4.1. For older versions you would use $HTTP_SERVER_VARS instead.

Mac
Buggy007
Forum Newbie
Posts: 4
Joined: Thu Jun 27, 2002 9:26 am

4.1.2

Post by Buggy007 »

hi,
I#m working with PHP 4.1.2 .. so this shouldn't be the problem... The registration works, but there's nothing left on the next page. I've got that feeling that there's something missing on this next page, but can't say what, session_start(); ist placed right on top...

(By the way, I tested with $HTTP_SERVER_VARS, it doesnt work, too.)
Buggy007
Forum Newbie
Posts: 4
Joined: Thu Jun 27, 2002 9:26 am

ok...

Post by Buggy007 »

if you use $_SESSION with PHP 4.1.2, you HAVE to register it by session_register("_SESSION");
Post Reply