Php Folks,
Check this out.
Why on 2nd page load, the ELSEIF does not trigger ?
My Expectation:
On the 1st page load, the IF should trigger since there are no sessions at the beginning.
But on the 2nd page load, the ELSEIF should trigger since a session has been started previously and form step had been set to ‘end’.
[code]
if(!session_id() || $_SESSION[‘form_step’] != ‘end’)
{
session_start();
$_SESSION[‘form_step’] = ‘start’;
echo “Line: 28 “; echo “Session Step: “; echo $_SESSION[‘form_step’]; echo “<br>”;
echo “Line: 29 “; echo “New Session Id: “; echo session_id(); echo “<br>”;
$_SESSION[‘form_step’] = ‘end’;
}
elseif($_SESSION[‘form_step’] == ‘end’) //Q2. WHY THIS IF GETS TRIGGERED WHEN CLICKING ANY NUMBERED PAGE LINKS (ON PAGINATION SECTION (EG PAGE 1 2 3 ETC.)) SINCE SESSION ID ALREADY EXISTS DUE TO [‘form_step’] = ‘end’ ?
{
//session_start();
echo “Line: 35 “; echo “Session Step: “; echo $_SESSION[‘form_step’]; echo “<br>”;
echo “Line: 36 “; echo “New Session Id: “; echo session_id(); echo “<br>”;
}
Guess what ? On 2nd page load or same page reload, even though a session exists, the ELSEIF doesn’t trigger but the IF triggers instead as if there are no sessions in existance or no sessions had been started yet.
Why is that ? Test the code on your own end and see for yourself. On the 1st page load, the IF will trigger. But refreshing the page would result in the same IF getting triggered again instead of the ELSEIF!