JonnySnip3r Posted August 10, 2010 Share Posted August 10, 2010 Hey guys not sure what this is called but does anyone have more information on it. Ok when you visit a part of a site or a profile or what ever?? :S:S and you redirect them to login how can u then send them back to where they was when they have logged in? hope someone can help. Link to comment https://forums.phpfreaks.com/topic/210388-remember-where-i-was-php-help/ Share on other sites More sharing options...
AdRock Posted August 10, 2010 Share Posted August 10, 2010 Are you on about using sessions? Say you try and view a restricted page like your user control panel and you are directed to a login page, after you login on you want to go back to the control panel page. The way i do it is check if a session has been registered and redirect to log in if not. After the user logs in you could use a header redirect to the control panel page or whatever. I have a function that redirects to a certain page after the user logs in Link to comment https://forums.phpfreaks.com/topic/210388-remember-where-i-was-php-help/#findComment-1097833 Share on other sites More sharing options...
freeloader Posted August 10, 2010 Share Posted August 10, 2010 I think I know what you mean. You try to load a page without being logged in, the page redirects you to login and you want it to redirect you back to the previous page right? I've made a similar home-grown solution for this on one of my sites, code went like this: $domain = parse_url($_SESSION["refer"]); $domain = str_replace("www.", "", $domain['host']); $host = str_replace("www.", "", $_SERVER['HTTP_HOST']); if($domain == $host) { header("location:".$_SESSION["refer"]); } else{ header("location:index.php"); } But I'm curious to see if anyone has a better one. Link to comment https://forums.phpfreaks.com/topic/210388-remember-where-i-was-php-help/#findComment-1097834 Share on other sites More sharing options...
AdRock Posted August 10, 2010 Share Posted August 10, 2010 What about using $_SERVER['HTTP_REFERER']? store that to a variable and redirect using the variable in header location Link to comment https://forums.phpfreaks.com/topic/210388-remember-where-i-was-php-help/#findComment-1097840 Share on other sites More sharing options...
JonnySnip3r Posted August 10, 2010 Author Share Posted August 10, 2010 YEAH!!! thats perfect thanks guys :D woo Link to comment https://forums.phpfreaks.com/topic/210388-remember-where-i-was-php-help/#findComment-1097841 Share on other sites More sharing options...
freeloader Posted August 10, 2010 Share Posted August 10, 2010 What about using $_SERVER['HTTP_REFERER']? store that to a variable and redirect using the variable in header location Yeah, but what if you came from another site follow a link to the site you just logged in to? It will go straight back to the (other) site you came from after login. That's why I do the domain check. No prob. Link to comment https://forums.phpfreaks.com/topic/210388-remember-where-i-was-php-help/#findComment-1097849 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.