Jump to content

Recommended Posts

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!

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.

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{
//[...]

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!

 

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.