Chesso Posted July 31, 2006 Share Posted July 31, 2006 Just wondering what people do about this? Like if a user tryed to access an area that required sign in and were redirected to the login page, how would you redirect them back to the page they wanted to access afterwards?Iv'e tryed a few things but never got it to work properly. Quote Link to comment https://forums.phpfreaks.com/topic/16067-redirect-on-login-general-idea/ Share on other sites More sharing options...
wildteen88 Posted July 31, 2006 Share Posted July 31, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/16067-redirect-on-login-general-idea/#findComment-66268 Share on other sites More sharing options...
king arthur Posted July 31, 2006 Share Posted July 31, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/16067-redirect-on-login-general-idea/#findComment-66278 Share on other sites More sharing options...
Chesso Posted August 10, 2006 Author Share Posted August 10, 2006 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). Quote Link to comment https://forums.phpfreaks.com/topic/16067-redirect-on-login-general-idea/#findComment-72226 Share on other sites More sharing options...
wildteen88 Posted August 10, 2006 Share Posted August 10, 2006 $_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 scriptecho $url;[/code] Quote Link to comment https://forums.phpfreaks.com/topic/16067-redirect-on-login-general-idea/#findComment-72395 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.