| Author |
session data getting lost
|
|
| jkmambo@gmail.com 2005-11-24, 3:57 am |
| Session data is getting lost in PHP version 4.4.1 which used to work in
version 4.3.3
The code is similar to the one below
Assume the file is called count.php which requires a parameter
productid;
session_start();
if (!isset($_SESSION['countAccess'])) $_SESSION['countAccess'] = 0;
else $_SESSION['countAccess']++;
echo $_SESSION['countAccess'];
if I call the script with a parameter for example
count.php?productid=78
when I press refresh button $_SESSION['countAccess'] does not get
incremented but if I call it without the parameter,
$_SESSION['countAccess'] gets incremented.
I am also losing data if I call another script.
Does anyone know what's going on here?
Thank you
| |
| Erwin Moller 2005-11-24, 3:57 am |
| jkmambo@gmail.com wrote:
> Session data is getting lost in PHP version 4.4.1 which used to work in
> version 4.3.3
>
> The code is similar to the one below
>
> Assume the file is called count.php which requires a parameter
> productid;
>
> session_start();
> if (!isset($_SESSION['countAccess'])) $_SESSION['countAccess'] = 0;
> else $_SESSION['countAccess']++;
>
> echo $_SESSION['countAccess'];
>
>
Why don't you use {} to mark your logical blocks?
This is PHP, not python. ;-)
Like:
session_start();
if (!isset($_SESSION['countAccess'])) {
$_SESSION['countAccess'] = 0;
} else {
$_SESSION['countAccess']++;
}
echo $_SESSION['countAccess'];
> if I call the script with a parameter for example
> count.php?productid=78
>
> when I press refresh button $_SESSION['countAccess'] does not get
> incremented but if I call it without the parameter,
> $_SESSION['countAccess'] gets incremented.
That ?productid=78 has nothing to do with the SESSION.
It will appear in $_GET, not $_SESSION.
So this is very surprising.
Do you have more code, without {}, that might interfere?
If yes: fix it, and if the problem persists, show us the code.
> I am also losing data if I call another script.
>
> Does anyone know what's going on here?
>
> Thank you
Regards,
Erwin Moller
| |
|
| Works for me on 3.3.10 and 4.4.1
Must be one of your settings or something elsewhere in the script
| |
| jkmambo@gmail.com 2005-11-24, 7:56 am |
| When you use one statement in an if-else block you dont need {} for all
C type languages. {} are only used to group statements
| |
| jkmambo@gmail.com 2005-11-24, 6:56 pm |
| I apologize the problem was not with the parameter. The code is working
sometimes and other times it does not work whether I am using a
paramter or not. The first time I tested the ecript today it was not
working, then I addeda simple echo statement to display a string. Then
the script worked OK. This is the setting of my session in php.ini
session
Session Support enabled
Registered save handlers files user
Directive Local Value Master Value
session.auto_start Off Off
session.bug_compat_42 On On
session.bug_compat_warn On On
session.cache_expire 180 180
session.cache_limiter 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_divisor 100 100
session.gc_maxlifetime 1440 1440
session.gc_probability 1 1
session.name PHPSESSID PHPSESSID
session.referer_check no value no value
session.save_handler files files
session.save_path /tmp /tmp
session.serialize_handler php php
session.use_cookies On On
session.use_only_cookies Off Off
session.use_trans_sid Off Off
| |
| jkmambo@gmail.com 2005-11-24, 6:56 pm |
| I apologize the problem was not with the parameter. The code is working
sometimes and other times it does not work whether I am using a
paramter or not. The first time I tested the ecript today it was not
working, then I addeda simple echo statement to display a string. Then
the script worked OK. This is the setting of my session in php.ini
session
Session Support enabled
Registered save handlers files user
Directive Local Value Master Value
session.auto_start Off Off
session.bug_compat_42 On On
session.bug_compat_warn On On
session.cache_expire 180 180
session.cache_limiter 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_divisor 100 100
session.gc_maxlifetime 1440 1440
session.gc_probability 1 1
session.name PHPSESSID PHPSESSID
session.referer_check no value no value
session.save_handler files files
session.save_path /tmp /tmp
session.serialize_handler php php
session.use_cookies On On
session.use_only_cookies Off Off
session.use_trans_sid Off Off
| |
| jkmambo@gmail.com 2005-11-24, 6:56 pm |
| I have discovered what the problem was. I installed Zone Alarm Internet
Security Suite and it appears its blocking the session information. I
have disabled it and the system is working fine now.
| |
|
| Sorry, still works every time, even with your ini file - could it be a
caching thing?
What OS and browser are you on?
| |
|
| Sorry, still works every time, even with your ini file - could it be a
caching thing?
What OS and browser are you on?
| |
| jkmambo@gmail.com 2005-11-24, 6:56 pm |
| The problem was being caused by zone alarm internet security software
blocking sessions. I do not understand why it's doing this for. I
wanted to buy it but now I will think twice before I buy it.
I thought the problem could have been due to my web hosting company
updating the PHP version and not setting up the session values
properly.
Thank you for taking your time to help me with this problem
| |
| Jerry Stuckle 2005-11-24, 6:56 pm |
| jkmambo@gmail.com wrote:
> When you use one statement in an if-else block you dont need {} for all
> C type languages. {} are only used to group statements
>
No, you don't *need* them. However, I still add them in my code.
Overall it makes things more readable, IMHO.
It also means I don't have unanticipated problems when I add another
statement to a then or else clause.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
| |
| jkmambo@gmail.com 2005-11-24, 6:56 pm |
| Erwin as implying that the braces are required in PHP even for one
statement but which they are not. In my opinion its more legible not to
have the braces and the code looks shorter.
| |
|
| I'd do a single line "if" as
if (!isset($_SESSION['countAccess'])) $_SESSION['countAccess'] = 0;
but if I had an else, i'd probably use braces, but I'd lay it out:
if (!isset($_SESSION['countAccess']))
{
$_SESSION['countAccess'] = 0;
}
else
{
$_SESSION['countAccess']++;
}
| |
|
| jkmambo@gmail.com wrote:
> Erwin as implying that the braces are required in PHP even for one
> statement but which they are not. In my opinion its more legible not to
> have the braces and the code looks shorter.
>
And harder to follow and maintain....
Ian
| |
|
| jkmambo@gmail.com wrote:
> The problem was being caused by zone alarm internet security software
> blocking sessions.
Was it blocking the session cookie? If so, this is a more general problem.
Ian
| |
| Erwin Moller 2005-11-25, 3:56 am |
| jkmambo@gmail.com wrote:
> When you use one statement in an if-else block you dont need {} for all
> C type languages. {} are only used to group statements
Hi mambo,
(Don't take this personal please.)
I was not saying your code was illigal or not working, I was just expressing
my annoyance with the style.
And I just wanted to tell you that your code looks a lot cleaner by adding
brackets.
I expect at least 99% of the PHP-community will to agree with that.
Shorter code isn't always better to read.
And I have seen my fair share of obscure errors that are difficult to
pinpoint due to sloppy codestyle.
(Sorry to call that code sloppy, but IMHO that style is sloppy.)
Anyway, this discussion doesn't solve your problem.
I'll read up in the other part of this thread, and if have something usefull
to tell, you'll notice. :-)
Regards,
Erwin Moller
|
|
|
|