?
Solved

PHP Redirect to completely different site

Posted on 2005-03-13
7
Medium Priority
?
302 Views
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?

0
Comment
Question by:rduval
7 Comments
 
LVL 32

Expert Comment

by:ldbkutty
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 )
0
 

Author Comment

by:rduval
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?
0
 
LVL 32

Expert Comment

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

It depends on the condition.

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

If still unclear, please show some code.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:ivantcc
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.

<?php
   // 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.
0
 

Accepted Solution

by:
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";

redirect("$url");


//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>";
      die;
}

?>
0
 
LVL 3

Expert Comment

by:Gianluigi_Zanettini-MegaLab_it
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!
0
 
LVL 6

Expert Comment

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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses

579 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