Session problem in IE and Google Chrome not in Mozilla Firefox
if(empty($_SESSION['count'])){
$_SESSION['count']=99;
}else{
$_SESSION['count']--;
}
echo $_SESSION['count'];
In Firefox, I get decrement开发者_JS百科ed value but in IE and Chrome it does not decrement the value as well as setting the value. Can anyone tell what's the problem?
This seems to work. Notice that i check for isset($_SESSION['temp']) here, not empty($_SESSION['count']:
<?php
session_start();
if(!isset($_SESSION['temp'])){
$_SESSION['temp']=99;
}else{
$_SESSION['temp']--;
}
echo $_SESSION['temp'];
?>
PHP code runs on the server, so every browser get's the same result. If it works with one browser but not with others, they have probably different settings. I would check, that all browsers allow setting of a session-cookie, otherwise they will start a new session every time they call your script.
As iHaveacomputer already pointed out, the function empty()
won't work in your example, because it will consider the value 0 as empty and therefore start counting with 99. Use isset()
or array_key_exists()
instead.
精彩评论