Re: session not working on a php page



On 13 Apr, 13:15, Suman <YoS...@xxxxxxxxx> wrote:
Hi All,

I am trying to experiment with sessions and they seem to be resetting
everytime i visit the page.

here is the code of the page

<?php
session_start();
$count = $_SESSION["counter"] + 1;
$_SESSION["counter"] = $count;
echo $_SESSION["counter"];
?>

if I refresh the page, the count doesn't increase. Whast should i do
to fix this?

any help is much appreciated

Find the problem - the code is fine. But the most common cause of
cookie related problems is output before a header or cookie realted
statement - PHP is very good at intercepting and reporting this - why
have you not checked your logs? Do you know how errors are recorded/
reported?

Even if that turns up nothing - you should look at the HTTP data
passing to and from the browser - you can use firebug or tamperdata
for Firefox, or iehttpheaders for MSIE. Or just sniff the traffic with
wireshark. Then you can verify if the server is presenting a cookie,
and if the browsers retruns it in subsequent requests.

C.
.



Relevant Pages

  • Re: [PHP] base64-encoding in cookies?
    ... The sender is in the driver's seat and the receiver must follow suite. ... PHP application is usually what set the cookie in the first place. ... You have control over the value you insert into the cookie. ...
    (php.general)
  • Re: [PHP] base64-encoding in cookies?
    ... PHP application is usually what set the cookie in the first place. ... $_SERVER fields are dependent on your http server. ... but my request is for documentation of the fact ...
    (php.general)
  • Re: Sessions
    ... click the link and in aoltest3.php the session variable is visable. ... Registered serializer handlers php php_binary wddx ... session.name PHPSESSID PHPSESSID ... see the PHPSESSID, in a cookie, or in the URL. ...
    (comp.lang.php)
  • Re: Cross-domain cookie updating ?
    ... It's not strictly a PHP question, but something that PHP guys would know the answer to. ... If the file being returned has updated cookie information in the response header, then I imagine the cookies for example.com get updated. ... What if the JS file it's requesting is actually to a different unrelated domain server that's going to return a JavaScript file with updated cookies in the response header. ... As far as I was aware, the only way a server can set a cookie in the response is by using server-side scripting. ...
    (comp.lang.php)
  • Re: Cross-domain cookie updating ?
    ... It's not strictly a PHP question, but something that PHP guys would know the answer to. ... If the file being returned has updated cookie information in the response header, then I imagine the cookies for example.com get updated. ... What if the JS file it's requesting is actually to a different unrelated domain server that's going to return a JavaScript file with updated cookies in the response header. ... As far as I was aware, the only way a server can set a cookie in the response is by using server-side scripting. ...
    (comp.lang.php)