Jump to content

[SOLVED] $_SERVER['HTTP_REFERER']


westminster86

Recommended Posts

I have a login / register link on the header of a page. If the users email address and password matches the values in the database, the user is redirected to the myaccount.php page. The showCart.php is a page displaying the items added to the shopping cart. I have a button, 'checkout', taking the user to the checkout.php page. At the start of the page I use the isset function to check the $_SESSION['user_fname'] isset. If not the user is redirected to the login.php.

The problem im having is, if the user has come to the login.php page via clicking the checkout button, id like the user to be taken to the checkout.php page. At the moment its taking the user to the myaccount.php page regardless.

 


$query = "select * from customers where emailaddress='$email'";
  $result = mysql_query($query, $db);

  $num_results = mysql_num_rows($result);

  if ($num_results>0) {
    $row = mysql_fetch_assoc($result);
    $encrypt = $row['password']; 

    if (crypt($password, $encrypt)==$encrypt) {
      $_SESSION['user_id'] = $row['customerid'];
      $_SESSION['user_fname'] = $row['firstname'];

      if ($_SERVER['HTTP_REFERER'] == 'http://www.collections.streamlinenettrial.co.uk/cgi-bin/checkout.php') {
        header ('Location: http://collections.streamlinenettrial.co.uk/cgi-bin/checkout.php');
      }
      else {
        header ('Location: http://collections.streamlinenettrial.co.uk/cgi-bin/myaccount.php');
      }
    }
    else {
      echo 'Sorry, we could not log you in with that password. <a href="login.php">Please go back and try again.</a>';
    }
  }
  else {
    echo 'Sorry, we could not recognise that email address. <a href="login.php">Please go back and try again.</a>';
  }

Link to comment
Share on other sites

Ah, yes of course. That would make sense seeing as that's the page the form is submitted from. You could, on the login page (login.php), store a hidden field called from or whatever if the referrer is the checkout page. Then you could on the login form processing page check if from is set and in that case redirect to that page.

Link to comment
Share on other sites

I forgot to mention that im appending the product Id of the item added to the cart to the end of the url. So it looks something like this,

http://www.collections.streamlinenettrial.co.uk/cgi-bin/showCart.php?new=1. So below, the user is going to be redirected to the checkout page only if the item with ID 1 is added to the cart. I have 193 products.


if ($_POST['from'] == 'http://www.collections.streamlinenettrial.co.uk/cgi-bin/showCart.php?new=1') {
   header ('Location: http://collections.streamlinenettrial.co.uk/cgi-bin/checkout.php');
}
else {
   header ('Location: http://collections.streamlinenettrial.co.uk/cgi-bin/myaccount.php');
} 

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.