Jump to content

Recommended Posts

I'm having a problem with remembering the destination someone was going to if it was a page that you need to be logged in to see.

I have it set up so that it redirects them the login page and the page they tried to go to is put in as a get value and upon logging in successfully, if that get variable is set to something it takes them to that page.

 

But when they successfully login, it just takes them to my index page and not the page they tried to go to. Any help?

 

I'm grabbing the URL using:

<?php
if (!$loggedin) {
$d = $_SERVER["REQUEST_URI"];
header("Location: login.php?d=$d");
exit;
}
?>

 

And the login part:

<?php
$loggedIn = FALSE;
if(isset($_POST["submit_login"])) {
if (isset($_POST)) {
	foreach ($_POST as $key => $val) {
		$_POST[$key] = myEscape($val);
	}
}
if (isset($_GET)) {
	foreach ($_GET as $key => $val) {
		$_GET[$key] = myEscape($val);
	}
}
$un =     $_POST["un"];
$pw = md5($_POST["pw"]);
dbconnect();
$query = "SELECT * FROM blog_users WHERE username='$un' AND password='$pw'";
$result = mysql_query($query) or DIE("Error: LOGIN. Contact Webmaster.");
if (mysql_num_rows($result) > 0) {
	$r = mysql_fetch_assoc($result);
	$user = $r["username"];
	$pass = $r["password"];
	if ($un == $user && $pw == $pass) {
		$_SESSION["user"] = $un;
		$loggedIn = TRUE;
		$loginError = FALSE;
		if (isset($_GET["d"])) {
			$d = $_GET["d"];
			header("Location: $d");
			exit;
		} else {
			header("Location: index.php");
			exit;
		}
	}
	$loginError = TRUE;
} else {
	$loginError = TRUE;
}
dbclose();
}
?>

Link to comment
https://forums.phpfreaks.com/topic/58761-solved-remembering-destination-link/
Share on other sites

your condition above is

if(isset($_POST["submit_login"])) { that means no get value will be set

 

heres your code prob

if (isset($_GET["d"])) {

$d = $_GET["d"];

header("Location: $d");

exit;

} else {

header("Location: index.php");

exit;

}

 

for sure that will false because the code works because isset submit right

but there will be no valu for the get so the distenation is???header("Location: index.php"); ;D

So you can't have POST and GET at the same time?

 

I wouldn't see why you couldn't....?

 

Are you sure the URL is setup when the user clicks submit? You would have to have your form action have the URL with the d=$d, or else it won't work.

 

Could you post the code to the form associated with this:

if(isset($_POST["submit_login"])) {

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.