Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You have three general approaches:</p> <ol> <li>Store the previous page in the session;</li> <li>Store the page as a GET variable; or</li> <li>Do an internal redirect to the login page.</li> </ol> <p>(1) looks something like:</p> <pre><code>&lt;?php session_start(); if (!$_SESSION['userid']) { $_SESSION['page'] = '/contact'; header('Location: /login'); exit; } ... ?&gt; </code></pre> <p>On successful login retrieve <code>$_SESSION['page']</code> and redirect.</p> <p>(2) is similar except there is no session variable. Instead you have:</p> <pre><code>header('Location: /login?return=/contact'); </code></pre> <p>to pass the redirect. The login page will have to include it as a hidden form field on the page that presents the user with a request for the username and password.</p> <p>(3) is similar but doesn't redirect to a separate page. Instead each page can potentially be a login page. If the user isn't logged in a login form is presented instead. The URL will still be "/contact". Each page will detect and handle log in attempts.</p> <p>The advantage of this method is one less external redirect and it's easier to handle submitted forms. By this I mean that imagine someone fills out a form on one of your pages and then clicks submit. The system sees their login has expired. If you redirect the user to a new page and then redirect back they will probably need to re-enter all the form fields. If you handle the login implicitly you can include all the form fields as hidden inputs and once logged in seamlessly treat it as a submission of the original page.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload