|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here! |
|
#1
|
|||
|
|||
|
Sessions once again
Hello, all!
I'll provide two pieces of code, which (from the functionality point of view) seem identical to me, but one of them (second) is working correctly, while the other is not. This situation is just driving me mad. Could please anyone help me? :angry: So here's the malfunctioning code: Code:
function & start () {
global $_SESSION;
if (!isset($_SESSION['count'])) {
$_SESSION['count'] = 0;
}
return $_SESSION['count'];
}
session_start ();
$count =& start();
$count++;
echo $_SESSION['count'] . ' -- <a href="test.php">Refresh</a>';
And here is the working one: Code:
session_start ();
if (!isset($_SESSION['count'])) {
$_SESSION['count'] = 0;
}
$count =& $_SESSION['count'];
$count++;
echo $_SESSION['count'] . ' -- <a href="test.php">Refresh</a>';
|
|
#2
|
|||
|
|||
|
RE: mysql?
$_SESSION is an autoglobal, so you don't need the:
global $_SESSION; take that line out and I think it will work as you expect... |
|
#3
|
|||
|
|||
|
RE: Sessions once again
Great! It works now. Thanks a lot, Matt. I will never forget it.
|
![]() |
| Viewing: Codewalkers Forums > PHP Related > PHP Coding > Sessions once again |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|
|