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
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

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

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.