shaunno2007 Posted June 27, 2008 Share Posted June 27, 2008 Hi i have a login on my website and i need it to Redirect people to the page that they where on before but i can not seem to do it. I have tryed this header("Location: ".$_SERVER['HTTP_REFERER']." "); but it keep comming up with this error message: Redirect Loop Firefox has detected that the server is redirecting the request for this address in a way that will never complete. The browser has stopped trying to retrieve the requested item. The site is redirecting the request in a way that will never complete. * Have you disabled or blocked cookies required by this site? * NOTE: If accepting the site's cookies does not resolve the problem, it is likely a server configuration issue and not your computer. And the login script what i am using is this: http://php.about.com/od/finishedphp1/ss/php_login_code.htm My website http://link-search.x10hosting.com/ Quote Link to comment https://forums.phpfreaks.com/topic/112183-login-redirect/ Share on other sites More sharing options...
neylitalo Posted June 27, 2008 Share Posted June 27, 2008 Sounds like the page you're redirecting to is redirecting back to the other page. Page 2 redirects to Page 1 Page 1 redirects to Page 2 Page 2 redirects to Page 1 And so on and so forth. You just need to find the redirect on Page 1 and fix the conditional logic around it. Quote Link to comment https://forums.phpfreaks.com/topic/112183-login-redirect/#findComment-575970 Share on other sites More sharing options...
shaunno2007 Posted June 27, 2008 Author Share Posted June 27, 2008 I have got it to stop looping but now when i login it stays on the login page but does not redirecting me back to the page ai was on before ??? I did the same on my logout page "header("Location: ".$_SERVER['HTTP_REFERER']." ");" and it works it redirects me to the page i was on before so i do not understand why it is not working on my login page Is they another way of redirecting to the page before because this way is not working for me??? Quote Link to comment https://forums.phpfreaks.com/topic/112183-login-redirect/#findComment-576052 Share on other sites More sharing options...
ag3nt42 Posted June 27, 2008 Share Posted June 27, 2008 easy answer.. meta redirect... run a condition if($login=="True") { echo('<meta http-equiv="refresh" content="2;url=http://yourSite.com">'); } the time above is in seconds.. aka 2secs before redirect Quote Link to comment https://forums.phpfreaks.com/topic/112183-login-redirect/#findComment-576176 Share on other sites More sharing options...
Jabop Posted June 27, 2008 Share Posted June 27, 2008 make sure to use die(); Quote Link to comment https://forums.phpfreaks.com/topic/112183-login-redirect/#findComment-576184 Share on other sites More sharing options...
br0ken Posted June 27, 2008 Share Posted June 27, 2008 I imagine that a user will try to access a page that will require authorisation and then this page will redirect the user to login page. When you redirect to the login page you need to tag the current page name onto the url. So for example, if you tried to access 'members.php' you would redirect the user to 'login.php?ref=members.php'. Then, on the login page you would create the following hidden input field and place it inside your login form. <input type="hidden" name="ref" value="<? echo strip_tags(addslashes(urldecode($_REQUEST['ref']))); ?>" /> Then once you've processed the login form you can check $_REQUEST['ref'] to for value and if you find one, redirect to that page. I have a system like this working on several of my websites at the minute and it works flawlessly. Quote Link to comment https://forums.phpfreaks.com/topic/112183-login-redirect/#findComment-576380 Share on other sites More sharing options...
shaunno2007 Posted June 29, 2008 Author Share Posted June 29, 2008 Well what i have done is that: when someone goes on to the page that you need to be logged in to. I have a if and else. so if they r logged in it will show the content that only the members can see but/else, if they are not logged in then they will be shown you need to login to. whatever do you understand what i mean if you dont just look at my website http://www.link-search.co.nr so could i use this so when they click on a link, then it will redirect the user to 'login.php?ref=members.php. Sort of thing ?? Quote Link to comment https://forums.phpfreaks.com/topic/112183-login-redirect/#findComment-577212 Share on other sites More sharing options...
br0ken Posted June 29, 2008 Share Posted June 29, 2008 I imagine that a user will try to access a page that will require authorisation and then this page will redirect the user to login page. When you redirect to the login page you need to tag the current page name onto the url. So for example, if you tried to access 'members.php' you would redirect the user to 'login.php?ref=members.php'. Then, on the login page you would create the following hidden input field and place it inside your login form. <input type="hidden" name="ref" value="<? echo strip_tags(addslashes(urldecode($_REQUEST['ref']))); ?>" /> Then once you've processed the login form you can check $_REQUEST['ref'] to for value and if you find one, redirect to that page. I have a system like this working on several of my websites at the minute and it works flawlessly. Yes you can. Obviously you will need to change the user_is_logged_in() function for your own authorisation test but the header part below will redirect a user to login.php and will tag the current page to the end of it. Then follow my steps in my post above and it should work. if (user_is_logged_in() == false) { header("Location: login.php?ref=".urlencode(basename($_SERVER['PHP_SELF'])."?".$_SERVER['QUERY_STRING'])); exit; } // If here, user is logged on so show content Quote Link to comment https://forums.phpfreaks.com/topic/112183-login-redirect/#findComment-577222 Share on other sites More sharing options...
shaunno2007 Posted June 29, 2008 Author Share Posted June 29, 2008 When someone clicks on a page that is for members i don't what it to redirect them to the login. When someone clicks on a link that says "login to see content" then it does your code do you need what i mean?? This is hard for me am all over place i thought it would be easy to do what i want but its coming a nightmare Quote Link to comment https://forums.phpfreaks.com/topic/112183-login-redirect/#findComment-577274 Share on other sites More sharing options...
br0ken Posted June 29, 2008 Share Posted June 29, 2008 Then on the 'Login to see content' link you simply append '?ref=pagename.html' to the end of the link where pagename.html' is the name of the page you want to redirect to after you login. Quote Link to comment https://forums.phpfreaks.com/topic/112183-login-redirect/#findComment-577276 Share on other sites More sharing options...
shaunno2007 Posted June 29, 2008 Author Share Posted June 29, 2008 Say a user is on my page called news.php and then they click on login to see content or lets just say login, then when they do it will do your code that you are saying then when they login, on login.php it will redirect them to news.php and then they will be logged in. Could you use some examples please as well thanks Quote Link to comment https://forums.phpfreaks.com/topic/112183-login-redirect/#findComment-577301 Share on other sites More sharing options...
br0ken Posted June 29, 2008 Share Posted June 29, 2008 What page is going to be password protected and have this content on? Quote Link to comment https://forums.phpfreaks.com/topic/112183-login-redirect/#findComment-577304 Share on other sites More sharing options...
Minase Posted June 29, 2008 Share Posted June 29, 2008 your english is really poor and thats why they dont understand what you want . try this .it might work history.go(-1) Quote Link to comment https://forums.phpfreaks.com/topic/112183-login-redirect/#findComment-577313 Share on other sites More sharing options...
shaunno2007 Posted June 29, 2008 Author Share Posted June 29, 2008 Where could i put this. <a href='javascript:history.back();'> i need it in my header this code it not right its just to give you an example: header("Location: <a href='javascript:history.back();'>"); Quote Link to comment https://forums.phpfreaks.com/topic/112183-login-redirect/#findComment-577354 Share on other sites More sharing options...
br0ken Posted June 29, 2008 Share Posted June 29, 2008 Rather than using header and redirecting back to the page you would display a page to the user saying... Thank you for logging in.<br /> <a href="javascript:history.back(-1);">Click here to return to your page</a><br /> If this doesn't work I would try -2 as opposed to -1. Quote Link to comment https://forums.phpfreaks.com/topic/112183-login-redirect/#findComment-577362 Share on other sites More sharing options...
shaunno2007 Posted June 29, 2008 Author Share Posted June 29, 2008 OK. I get it like on a forum it says redirecting you to your page something like that i will just make another page called redirecting and then put that they right thanks for your very helpful comment Shaun Quote Link to comment https://forums.phpfreaks.com/topic/112183-login-redirect/#findComment-577603 Share on other sites More sharing options...
shaunno2007 Posted June 29, 2008 Author Share Posted June 29, 2008 Its weird right i put <a href="javascript:history.back(-1);">Click here to return to your page</a> did not work it redirected me to the login again so i tryed <a href="javascript:history.back(-2);">Click here to return to your page</a> Still nothing wtf don't get it plus i need it to refresh the page cos it not show you user logged in if it takes them back using history -2 or -1 Quote Link to comment https://forums.phpfreaks.com/topic/112183-login-redirect/#findComment-577630 Share on other sites More sharing options...
br0ken Posted June 29, 2008 Share Posted June 29, 2008 I imagine that a user will try to access a page that will require authorisation and then this page will redirect the user to login page. When you redirect to the login page you need to tag the current page name onto the url. So for example, if you tried to access 'members.php' you would redirect the user to 'login.php?ref=members.php'. Then, on the login page you would create the following hidden input field and place it inside your login form. <input type="hidden" name="ref" value="<? echo strip_tags(addslashes(urldecode($_REQUEST['ref']))); ?>" /> Then once you've processed the login form you can check $_REQUEST['ref'] to for value and if you find one, redirect to that page. I have a system like this working on several of my websites at the minute and it works flawlessly. Yes you can. Obviously you will need to change the user_is_logged_in() function for your own authorisation test but the header part below will redirect a user to login.php and will tag the current page to the end of it. Then follow my steps in my post above and it should work. if (user_is_logged_in() == false) { header("Location: login.php?ref=".urlencode(basename($_SERVER['PHP_SELF'])."?".$_SERVER['QUERY_STRING'])); exit; } // If here, user is logged on so show content This is why you need the code I suggested. It may seem hard for you to integrate it into your site but if you understand it properly it's quite simple. I know it works because I have it in use of every site I maintain that has a login system. Quote Link to comment https://forums.phpfreaks.com/topic/112183-login-redirect/#findComment-577632 Share on other sites More sharing options...
shaunno2007 Posted June 30, 2008 Author Share Posted June 30, 2008 Yes, but if i use the code that you suggested then when someone goes on that page with that code in it will redirect them to the login, but i dont want that because if i did then i would have to have it on every page because i have a login link on all my pages. Quote Link to comment https://forums.phpfreaks.com/topic/112183-login-redirect/#findComment-577919 Share on other sites More sharing options...
MasterACE14 Posted June 30, 2008 Share Posted June 30, 2008 I'm too lazy to go and read all the posts in your topic... but from what I've read on this page, you can use this method: <?php header("Location: index.php"); // or whatever page you want to redirect to Regards ACE Quote Link to comment https://forums.phpfreaks.com/topic/112183-login-redirect/#findComment-577925 Share on other sites More sharing options...
shaunno2007 Posted June 30, 2008 Author Share Posted June 30, 2008 That is what i was doing at start thanks anyway MasterACE14 Quote Link to comment https://forums.phpfreaks.com/topic/112183-login-redirect/#findComment-577965 Share on other sites More sharing options...
MasterACE14 Posted June 30, 2008 Share Posted June 30, 2008 no problem. So is the problem solved? or you still got a problem? if so , start all over Quote Link to comment https://forums.phpfreaks.com/topic/112183-login-redirect/#findComment-577969 Share on other sites More sharing options...
shaunno2007 Posted June 30, 2008 Author Share Posted June 30, 2008 I imagine that a user will try to access a page that will require authorisation and then this page will redirect the user to login page. When you redirect to the login page you need to tag the current page name onto the url. So for example, if you tried to access 'members.php' you would redirect the user to 'login.php?ref=members.php'. Then, on the login page you would create the following hidden input field and place it inside your login form. <input type="hidden" name="ref" value="<? echo strip_tags(addslashes(urldecode($_REQUEST['ref']))); ?>" /> Then once you've processed the login form you can check $_REQUEST['ref'] to for value and if you find one, redirect to that page. I have a system like this working on several of my websites at the minute and it works flawlessly. Yes you can. Obviously you will need to change the user_is_logged_in() function for your own authorisation test but the header part below will redirect a user to login.php and will tag the current page to the end of it. Then follow my steps in my post above and it should work. if (user_is_logged_in() == false) { header("Location: login.php?ref=".urlencode(basename($_SERVER['PHP_SELF'])."?".$_SERVER['QUERY_STRING'])); exit; } // If here, user is logged on so show content This is why you need the code I suggested. It may seem hard for you to integrate it into your site but if you understand it properly it's quite simple. I know it works because I have it in use of every site I maintain that has a login system. What i need is a onclick sort of thing so when people click on a link it will take them to the login plus it will do this as (When they click it) header("Location: login.php?ref=".urlencode(basename($_SERVER['PHP_SELF'])."?".$_SERVER['QUERY_STRING'])); exit; Quote Link to comment https://forums.phpfreaks.com/topic/112183-login-redirect/#findComment-578410 Share on other sites More sharing options...
shaunno2007 Posted July 3, 2008 Author Share Posted July 3, 2008 I imagine that a user will try to access a page that will require authorisation and then this page will redirect the user to login page. When you redirect to the login page you need to tag the current page name onto the url. So for example, if you tried to access 'members.php' you would redirect the user to 'login.php?ref=members.php'. Then, on the login page you would create the following hidden input field and place it inside your login form. <input type="hidden" name="ref" value="<? echo strip_tags(addslashes(urldecode($_REQUEST['ref']))); ?>" /> Then once you've processed the login form you can check $_REQUEST['ref'] to for value and if you find one, redirect to that page. I have a system like this working on several of my websites at the minute and it works flawlessly. Yes you can. Obviously you will need to change the user_is_logged_in() function for your own authorisation test but the header part below will redirect a user to login.php and will tag the current page to the end of it. Then follow my steps in my post above and it should work. if (user_is_logged_in() == false) { header("Location: login.php?ref=".urlencode(basename($_SERVER['PHP_SELF'])."?".$_SERVER['QUERY_STRING'])); exit; } // If here, user is logged on so show content This is why you need the code I suggested. It may seem hard for you to integrate it into your site but if you understand it properly it's quite simple. I know it works because I have it in use of every site I maintain that has a login system. What i need is a onclick sort of thing so when people click on a link it will take them to the login plus it will do this as (When they click it) header("Location: login.php?ref=".urlencode(basename($_SERVER['PHP_SELF'])."?".$_SERVER['QUERY_STRING'])); exit; Quote Link to comment https://forums.phpfreaks.com/topic/112183-login-redirect/#findComment-580993 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.