Reputation: 49
Standalone page navigation problems i mean in a project i have more than 5 pages. User compulsory to follow the order to navigate the pages(page 1 -> page 2 -> page 3....). If the user directly hits the the page 3 i am redirecting to 1st page. i am doing like this In page 1 when user clicks the submit button it self i am added the variable to session (usernamespace-> navpage = 'page 2')
and in page 2 to i am checking
if(usernamespace-> navpage == 'page 2')
//nothing
else
redirecting to page 1;
I have a problem when i am in 3rd page user clicks the browsers back button it will not redirect to 2nd page because usernamespace-> navpage == 'page 3' in history.
Please suggest me to change the navigation's logic which is not related affected to above browser issue.
Upvotes: 0
Views: 114
Reputation: 20469
Make your session data an array, and set keys according to pages completed:
//page1
$_SESSION['pages']=[];
$_SESSION['pages'][1]=true;
//page2
if(!isset($_SESSION['pages'][1])
//redirect
$_SESSION['pages'][2]=true;
//page3
if(!isset($_SESSION['pages'][2])
//redirect
$_SESSION['pages'][3]=true;
//etc etc
Upvotes: 1
Reputation: 1078
Hope I understand your question correctly. Could you put an OR in there?
if(usernamespace-> navpage == 'page 2' || usernamespace-> navpage == 'page 3' )
//nothing
or if that doesn't suit your application you could make another session var that is the previous page... this variable gets the previous value when navpage gets updated..
User clicks submit on page 1 and:
usernamespace-> navpage = 'page 2'
usernamespace-> prevpage = 'page 1'
Then on page 2 you have...
if(usernamespace-> navpage == 'page 2' || usernamespace-> prevpage == 'page 2')
//nothing
Then when the user gets to page 3 just make sure the prepage stays at 'page 2' as long as they don't submit.
Upvotes: 0