rmelino Posted September 9, 2009 Share Posted September 9, 2009 Hello, I've been struggling with this for the last few hours and can't seem to figure out what the problem is... I want the user to be able to click on a link in an email which contains an id variable. I want that link to bring them to their login page. Once they login, i want that same id variable to pass over to the url that the login resolves to upon successful login. The link in the email looks something like this: http://www.mysite.com/login.php?id=12345 the php code i have on the login.php page looks like this: <?php session_start(); require("phpsqlajax_dbinfo_new.php"); $leadid = $_GET["id"]; if(isset($_POST['login'])) { $username = trim(addslashes($_POST['username'])); $password = md5(trim($_POST['password'])); $query = mysql_query("SELECT * FROM Users WHERE username = '$username' AND password = '$password' LIMIT 1") or die(mysql_error()); $row = mysql_fetch_array($query); // now we check if they are activated if(mysql_num_rows($query) > 0) { if($row['activated'] > 0) { $_SESSION['s_logged_n'] = 'true'; $_SESSION['s_username'] = $username; $_SESSION['s_name'] = $row['name']; header("Location: buy.php?leadid=" . $leadid); } else { If this was working properly, once logged in, in this example the URL should resolve to: http://www.mysite.com/buy.php?leadid=12345 Instead, it just resolves to: http://www.mysite.com/buy.php?leadid= I can't figure out why it is not passing through the variable after login. Please help! Quote Link to comment https://forums.phpfreaks.com/topic/173724-problem-passing-variable-to-headerlocation/ Share on other sites More sharing options...
sKunKbad Posted September 9, 2009 Share Posted September 9, 2009 how about: header("Location: buy.php?leadid=$leadid"); Quote Link to comment https://forums.phpfreaks.com/topic/173724-problem-passing-variable-to-headerlocation/#findComment-915746 Share on other sites More sharing options...
rmelino Posted September 9, 2009 Author Share Posted September 9, 2009 nope, tried that and no luck... Quote Link to comment https://forums.phpfreaks.com/topic/173724-problem-passing-variable-to-headerlocation/#findComment-915752 Share on other sites More sharing options...
PFMaBiSmAd Posted September 9, 2009 Share Posted September 9, 2009 The php code you posted is the target of your login form submission. You have got pass the ?id=12345 through the actual form somehow, either on the end of the URL or as a hidden field in the form. Quote Link to comment https://forums.phpfreaks.com/topic/173724-problem-passing-variable-to-headerlocation/#findComment-915760 Share on other sites More sharing options...
rmelino Posted September 10, 2009 Author Share Posted September 10, 2009 Hi, Thanks for the response. How would i have the buy.php page read the hidden id=12345 that i pass through the login page? Quote Link to comment https://forums.phpfreaks.com/topic/173724-problem-passing-variable-to-headerlocation/#findComment-915766 Share on other sites More sharing options...
keldorn Posted September 10, 2009 Share Posted September 10, 2009 When they reach the "login" page. Save the Variable $leadid as a $_SESSION like $_SESSION['leadid'] = $_GET['id']; When they hit their POST and your script returns the new page, pass the $_SESSION['leadid'] as header("Location: buy.php?leadid=" . $_SESSION['leadid']); How about that? I think it would work if I'm understanding correctly. Quote Link to comment https://forums.phpfreaks.com/topic/173724-problem-passing-variable-to-headerlocation/#findComment-915837 Share on other sites More sharing options...
rmelino Posted September 10, 2009 Author Share Posted September 10, 2009 keldorn, unfortunately that is not working either Quote Link to comment https://forums.phpfreaks.com/topic/173724-problem-passing-variable-to-headerlocation/#findComment-915889 Share on other sites More sharing options...
keldorn Posted September 10, 2009 Share Posted September 10, 2009 keldorn, unfortunately that is not working either Make sure you put the $_SESSION['leadid'] = $_GET['id']; to set the sesssion cookie when they first hit the login page. So the cookie is available when the hit post. (the cookie should get sent with their post?). I think that it should work or it might be becuase of the header redirect. I've heard that header(); can mess with sessions. So maby try this. //[...] $_SESSION['s_logged_n'] = 'true'; $_SESSION['s_username'] = $username; $_SESSION['s_name'] = $row['name']; $leadid = $_SESSION['leadid']; session_write_close(); header("Location: buy.php?leadid=" . $leadid); exit; }else{ //[...] Quote Link to comment https://forums.phpfreaks.com/topic/173724-problem-passing-variable-to-headerlocation/#findComment-915962 Share on other sites More sharing options...
phpretard Posted September 10, 2009 Share Posted September 10, 2009 This works for me: $leadid=$_SESSION['leadid']; header ("location: buy.php?leadid={$leadid}"); Quote Link to comment https://forums.phpfreaks.com/topic/173724-problem-passing-variable-to-headerlocation/#findComment-915997 Share on other sites More sharing options...
rmelino Posted September 10, 2009 Author Share Posted September 10, 2009 got it working! i think what i was doing wrong was: originally i had session_start(); $_SESSION['leadid'] = $_GET['id']; i changed to this and it works: $_SESSION['leadid'] = $_GET['id']; session_start(); Thanks for all your help! Quote Link to comment https://forums.phpfreaks.com/topic/173724-problem-passing-variable-to-headerlocation/#findComment-916131 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.