I am new to this, i am creating a site with a shopping cart. I have a main login page that already redirect the users to the homepage if they tries to login from this page, no issues with this. However i have a another page (checkout page) which direct the users to a login page if they have selected an item to purchased but have not yet sign in, after login from this page it genetically redirect to the homepage. How can make it so that it will go back to the checkout page if the users logs in from here?
if (count($_SESSION['prodquan']) != 0) { print "<table border='1' align='center' width='50%'>"; print "<tr><td colspan='5' style='color:red'>"; if (isset($_SESSION['username'])) print 'Hello ' . $_SESSION['username']; print "</td></tr>"; print "<caption style='font-size:20;color:red'>Shopping Cart</caption>"; print "<tr>"; print "<td>Product Id</td><td>Product Description</td><td>Quantity</td><td>Price</td><td>Cost</td></tr>"; foreach ($_SESSION['prodquan'] as $prod=>$quan) { $query = "select productdescription, price from product where productid = $prod"; $result = mysqli_query($conn, $query); $row = mysqli_fetch_array($result); $cost = $row[1]*$quan; print "<tr><td>$prod</td><td>$row[0]</td><td>$quan</td><td>$row[1]</td><td>$cost</td></tr>"; $_SESSION['totalcost'] += $cost; mysqli_free_result($result); } print "<tr align='right'><td colspan='4'>Total Cost:</td><td>" . $_SESSION['totalcost'] . "</td></tr>"; print "</table>"; print "<table border='0' width='50%' align='center'>"; print "<tr rowspan='2'>"; print "<td align='center'><a href='checkout.php?payment=yes'>Payment</a>  <a href='validpage.php'>Products</a>  <a href='logout.php'>logout</a></td>"; print "</tr>"; print "</table>"; } else { $errormessage = " The shopping cart is empty"; header("location:validpage.php?errormsg=$errormessage"); exit(); } if (@$_GET['payment'] == "yes") { if (!isset($_SESSION['username'])) { $errormessage = "Please login"; header("location:http://localhost/shoppingcart/?page_id=5?errormsg=$errormessage"); exit(); } //$_SESSION['payment'] = "yes"; print "<td align='center'><a href='checkout.php?credit=yes'>Credit Card</a>  <a href='checkout.php?cheque=yes'>Cheque</a>  <a href='checkout.php?american=yes'>American Express</a></td>"; //unset($_GET['payment']); } Many thanks