?
Solved

PHP Redirect to completely different site

Posted on 2005-03-13
7
Medium Priority
?
291 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
[X]
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
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
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.

 
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

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