westminster86 Posted April 11, 2008 Share Posted April 11, 2008 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>'; } Quote Link to comment Share on other sites More sharing options...
westminster86 Posted April 11, 2008 Author Share Posted April 11, 2008 Im not all that familiar with $_SERVER['HTTP_REFERER'] so I dont know if im using it right. Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted April 11, 2008 Share Posted April 11, 2008 Try to output $_SERVER['HTTP_REFERER'] to see what it actually contains. That'll give you an idea of what you need to change the if statement to. Quote Link to comment Share on other sites More sharing options...
westminster86 Posted April 11, 2008 Author Share Posted April 11, 2008 I echoed $_SERVER['HTTP_REFERER'] and I got, http://www.collections.streamlinenettrial.co.uk/cgi-bin/login.php Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted April 11, 2008 Share Posted April 11, 2008 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. Quote Link to comment Share on other sites More sharing options...
westminster86 Posted April 11, 2008 Author Share Posted April 11, 2008 Ill try that. Quote Link to comment Share on other sites More sharing options...
westminster86 Posted April 11, 2008 Author Share Posted April 11, 2008 so does the hidden field have the value "http://collections.streamlinenettrial.co.uk/cgi-bin/checkout.php" ? Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted April 11, 2008 Share Posted April 11, 2008 Yes, providing that's where you came from before you got to the login form. Quote Link to comment Share on other sites More sharing options...
westminster86 Posted April 11, 2008 Author Share Posted April 11, 2008 How do I extract the hidden field's value on the page that process's the login form? Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted April 11, 2008 Share Posted April 11, 2008 $_POST['from'] (or whatever name you choose for the field) Quote Link to comment Share on other sites More sharing options...
westminster86 Posted April 11, 2008 Author Share Posted April 11, 2008 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'); } Quote Link to comment 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.