Jump to content

Remember where i was? php help


JonnySnip3r

Recommended Posts

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

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

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.