soycharliente Posted July 6, 2007 Share Posted July 6, 2007 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(); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/58761-solved-remembering-destination-link/ Share on other sites More sharing options...
pocobueno1388 Posted July 6, 2007 Share Posted July 6, 2007 In the first part of your code, you have the variable set to $loggedin, then in the second part you have it as $loggedIn. So maybe you should change this line: if (!$loggedin) { To: if (!$loggedIn) { Quote Link to comment https://forums.phpfreaks.com/topic/58761-solved-remembering-destination-link/#findComment-291523 Share on other sites More sharing options...
soycharliente Posted July 6, 2007 Author Share Posted July 6, 2007 That didn't work. Quote Link to comment https://forums.phpfreaks.com/topic/58761-solved-remembering-destination-link/#findComment-291543 Share on other sites More sharing options...
sasa Posted July 6, 2007 Share Posted July 6, 2007 what function myEscape() doing Quote Link to comment https://forums.phpfreaks.com/topic/58761-solved-remembering-destination-link/#findComment-291580 Share on other sites More sharing options...
soycharliente Posted July 6, 2007 Author Share Posted July 6, 2007 <?php function myEscape($string) { dbconnect(); $new = get_magic_quotes_gpc() ? stripslashes($string) : $string; return mysql_real_escape_string($new); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/58761-solved-remembering-destination-link/#findComment-291657 Share on other sites More sharing options...
teng84 Posted July 6, 2007 Share Posted July 6, 2007 if (isset($_GET["d"])) { $d = $_GET["d"]; header("Location: $d"); exit; } else { header("Location: index.php"); exit; } the code always generate the else Quote Link to comment https://forums.phpfreaks.com/topic/58761-solved-remembering-destination-link/#findComment-291663 Share on other sites More sharing options...
teng84 Posted July 6, 2007 Share Posted July 6, 2007 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"); Quote Link to comment https://forums.phpfreaks.com/topic/58761-solved-remembering-destination-link/#findComment-291666 Share on other sites More sharing options...
soycharliente Posted July 7, 2007 Author Share Posted July 7, 2007 So you can't have POST and GET at the same time? Quote Link to comment https://forums.phpfreaks.com/topic/58761-solved-remembering-destination-link/#findComment-291716 Share on other sites More sharing options...
pocobueno1388 Posted July 7, 2007 Share Posted July 7, 2007 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"])) { Quote Link to comment https://forums.phpfreaks.com/topic/58761-solved-remembering-destination-link/#findComment-291726 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.