PHP Redirect to completely different site

Posted on 2005-03-13
Medium Priority
Last Modified: 2012-05-05
I'm taking info from a form posting, generating an email then I want to redirect to a completely different site (paypal actually to process the payment).

That site will kick back to me when I'm done but how do I get to the other site?

I've tried using:

Header("Location: https://www.paypal.com/xclick/business=paypal%40nl4x4%2eca&undefined_quantity=1&item_name=Northern%20Lights%204x4%20Trailriders%20Assoc%20Membership&amount=25%2e00&no_shipping=1&return=http%3a%2f%2fwww%2enl4x4%2eca%2fsignup%2fcomplete%2ephp¤cy_code=CAD");

but I get:

Warning: Cannot modify header information - headers already sent by (output started at C:\vhome\nl4x4\signup\sendmail_gopaypal.php:9) in C:\vhome\nl4x4\signup\sendmail_gopaypal.php on line 26

Any ideas kids?

Question by:rduval
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 32

Expert Comment

ID: 13531843
The "header" function should be sent before any ouput (HTML or echo tags) is sent to the browser.

There should not be even a single white space before the php starting tag.

I mean :

<?php // correct.

  <?php // wrong, notice the white space before the <?php tag.

Possible solutions are :

1) Move the echo statements (if any) in your code after all the header functions.  ( OR )

2) Assign the echo statements in a variable and call it after the header function.

3) Set output buffering ( http://www.php.net/ob_start )

Author Comment

ID: 13537069
I need something I can do at the end, after all the other scripting is done.

If I call the header first won't it re-direct me before anything else is done?
LVL 32

Expert Comment

ID: 13538887
> If I call the header first won't it re-direct me before anything else is done?

It depends on the condition.

if(something IS true) {
 header("Location: http://www.domain.com");
else {
 echo "something is false, you can echo the display here";

If still unclear, please show some code.
WordPress Tutorial 1: Installation & Setup

WordPress is a very popular option for running your web site and can be used to get your content online quickly for the world to see. This guide will walk you through installing the WordPress server software and the initial setup process.


Expert Comment

ID: 13541947
Try the following meta tag(quick and dirty method)
It can redirect your page even after you output anything. Although it's not recommended.

   // target of the redirect
   $url = "https://www.paypal.com/";

   // 0 second delay
   $delay = "0";

   echo '<meta http-equiv="refresh" content="'.$delay.';url='.$url.'">';

The meta goes in the head of the HTML, or anywhere else.
This method does not require javascript and is supported by most browsers and is rarely, if ever, filtered out.

Accepted Solution

Ongki earned 500 total points
ID: 13542437

//your processing codes

//end processing, let's redirect to paypal
$url = "https://www.paypal.com/xclick/business=paypal%40nl4x4%2eca&undefined_quantity=1&item_name=Northern%20Lights%204x4%20Trailriders%20Assoc%20Membership&amount=25%2e00&no_shipping=1&return=http%3a%2f%2fwww%2enl4x4%2eca%2fsignup%2fcomplete%2ephp¤cy_code=CAD";


//function to redirect to a a specific url($url)
//can even show an optional message($message)
//for a given optional $delay time

function redirect($url, $message="", $delay=0) {
/* redirects to a new URL using meta tags */
      echo "<meta http-equiv='Refresh' content='$delay; url=$url'>";
                if (!empty($message)) echo "<div style='font-family: Arial, Sans-serif; font-size: 12pt;' align=center>$message</div>";


Expert Comment

ID: 13617299
Just add ob_start(); as first line in your php script!

I was having the same problem and got it fixed with this!

Expert Comment

ID: 13656284
Only if you add ob_end_flush() at the end as well.

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Matthew
I am a very big proponent of technology compliance standards and strive to meet such criteria in all of my work. That includes my site, which is 100% XHTML 1.0 compliant as determined by the World Wide Web Consortium. https://www.matthewstevenkel…
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question