Jump to content

PHP Header Redirect URL


WebDeveloperMike

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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:

Link to comment
Share on other sites

  • 2 months later...

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...