Jump to content

Recommended Posts

Posted

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

Posted

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.

Posted

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. :rolleyes:

  • 2 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...