WebDeveloperMike Posted January 30, 2012 Report Share Posted January 30, 2012 Here is my question: Since the php engine reads code from top to bottom, why does the code below the header redirect continue to process once it has navigated away from the page? Here is my code: <?php require_once '../functions/functions.php'; header('Location: http://www.mikespot.net/PaypalShoppingCart/html/viewCart.php'); $shopping_cart = get_shopping_cart(); echo render_header(); $product_id = $_REQUEST['id']; if (product_exists($product_id)) $shopping_cart->AddItem($product_id); set_shopping_cart($shopping_cart); echo render_paypal_checkout($shopping_cart); echo render_footer(); END OF CODE ----------------------------------------------------------------------------------------- Thanks, Mike Quote Link to comment Share on other sites More sharing options...
Symphlion Posted January 30, 2012 Report Share Posted January 30, 2012 Please explain. A header() forces the browser to go to a new page. It should stop executing that file inmediatly unless specified otherwise. If you don`t trust this, you can force the exit yourself like this: header("Location: path/to/new/file.php"); exit(); It`s not a clean way of handling it, but it will stop executing that very page until PHP picks up on the new header location. Just remember, headers() can ONLY be sent while there is no output! So if you echo something out and start using the header(), you will trigger an error with something like: Headers already sent. Quote Link to comment Share on other sites More sharing options...
WebDeveloperMike Posted February 2, 2012 Author Report Share Posted February 2, 2012 all of the code below the header does in fact work. ive used the shopping cart with paypal sandbox and live on paypal and it works exactly the same as before I put the header function code in. Its doing what i want it to do, so im glad it works, but im just confused because i thought for sure if I put the header code in there it wouldnt work - but it did. now im curious as to why. Quote Link to comment Share on other sites More sharing options...
andersonjohn Posted April 4, 2012 Report Share Posted April 4, 2012 Using headers() method, you can easily transferred to the new page without having to click a link to continue. This is also useful for search engines. 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.
Note: Your post will require moderator approval before it will be visible.