Jump to content

Variable from link in e-mail is cut off once user logs in...


mjurmann

Recommended Posts

Hello. Every time I add an update to a user's account on my website, I have an auto e-mail sent out to the user. It is formatted with HTML and includes a hyperlink. This hyperlink will be in the form of http:/www.domainname.com/page.php?variable . Once they click on it, they will be forced to login to the site since that page is restricted to clients only. Once they login in, I want them to be forwarded to that initial link that they clicked on. Instead, they are forwarded to http://www.domainname.com/page.php - The variable seems to get cut off. Can someone please assist me with keeping the url intact including the variable at the end?

 

Here is my code:

 

<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
  session_start();
  $_SESSION['MM_Username'] = NULL;
}

$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
  $_SESSION['PrevUrl'] = $_GET['accesscheck'];
}

if (isset($_POST['Email'])) {
  $loginUsername=$_POST['Email'];
  $password=$_POST['Password'];
  $MM_fldUserAuthorization = "authorized";
  $MM_redirectLoginSuccess = $_SESSION['PrevUrl']; // I think the problem might be here

  $MM_redirectLoginFailed = "login-failed.php";
  $MM_redirecttoReferrer = false;
  mysql_select_db($database_Chromatic, $Chromatic);
  	
  $LoginRS__query=sprintf("SELECT email, password, authorized FROM clients WHERE email='%s' AND password='%s'",
  get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password)); 
   
  $LoginRS = mysql_query($LoginRS__query, $Chromatic) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
    
    $loginStrGroup  = mysql_result($LoginRS,0,'authorized');
    
    //declare two session variables and assign them
    $_SESSION['MM_Username'] = $loginUsername;
    $_SESSION['MM_UserGroup'] = $loginStrGroup;	      

    if (isset($_SESSION['PrevUrl']) && false) {
      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];	
    }
    header("Location: " . $MM_redirectLoginSuccess );
  }
  else {
    header("Location: ". $MM_redirectLoginFailed );
  }
}
?>

Link to comment
Share on other sites

Your code is very confusing... and you didn't give very much information about what your variables are for.

 

First of all, I notice that you declare

<?php $loginFormAction = $_SERVER['PHP_SELF']; ?>

 

Then never use that information again.

 

Some of your stuff seems a bit... strange to me

<?php if(isset($_SESSION['PrevUrl']) && false) ?>

 

Are you saying... if that session variable exists, and false exists? I assume you meant to say

<?php if(isset($_SESSION['PrevUrl'])===FALSE) ?>

 

Seems to me that a way to simplify this whole process is to basicly say...

 

If login was successful then gotoLocation = success_url

If login failed then gotoLocation = failed_url

 

That way you can get rid of one of your header() lines.

 

That's pretty much the best I can do, it would take me a lot more time to actually figure out what your code is doing... but it seems to need some work. Or... I'm just a novice at php and I have no idea what I'm talking about :P

Link to comment
Share on other sites

I appreciate the response, however, it didn't fix the problem.

 

Now my question is quite simple:

 

Is it possible to take a variable from a URL such as admin-home.php?id=001 where 001 is the data from the id variable and then perform a series of conditional statements before the <head></head> tags. It seems that when I try to $_GET['id'] in the area before the <head> </head> tags the id variable is null. However, when I echo that same variable out in the body, the id echoes out correctly.

 

Simple question...anyone?

 

Thanks so much

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.