Jump to content

Recommended Posts

Either set a cookie or a session which will hold the location they was before being redirected to the login page. Then when they successfully login you check whether the redirect cookie/session is set. If it is you redirect them, if its not you redirect them to your homepage.
The way I do it is to have a call to an authorize function near the start of the script for each page that is restricted to members only. The function returns true or false and does three things.  First it checks to see if the user is logged in. If so it returns true. If not, it checks to see if a valid username and password was supplied, and if so it logs the user in and returns true. Otherwise it renders a login form and returns false - the "action" parameter of the form is set to the same page as the calling script using the $SERVER["PHP_SELF"] superglobal.  On return from the function, if the return was false, I just end the script there instead of rendering the rest of the page. So, as soon as the user successfully logs in they will be returned to the same page which is then rendered fully.

It works for me, it may not be the way everyone does it.
  • 2 weeks later...
Well I was using __FILE__ in combination with $_SERVER['QUERY_STRING'] but I can't test locally (which I need to) because instead of using http://localhost it puts the literal location (I can't use PHP_SELF because it doesn't include the site url like www.chessoscorner.com for example).
$_SERVER['PHP_SELF] retrieves the relative path to the servers document root (the main directory your files get uploaded to for your website). If you want to have your sites url prepended before $_SERVER['PHP_SELF'] use:
[code=php:0]$url = $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF'];

// now $url holds the url and the location of the script
echo $url;[/code]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.