0

I have a site that contains multiple objects (form, menu bar, etc).

At the same time, I am "including" with PHP another page that contains an API making a request. When this page will receive a response, it does the following:

header('Location: ' . $url);

However, the issue is that I want this redirection to happen within my own page. The issue is that I get the typical error: "Warning: Cannot modify header information - headers already sent by.." right before the header('Location... gets executed.

I guess I cannot do the redirect while staying in the same page?

How could I fix this so I can stay in the same page while the API runs the request and response and then displays the result?

Thanks

Sam
  • 7,252
  • 16
  • 46
  • 65
samyb8
  • 2,560
  • 10
  • 40
  • 68
  • Let me see if I got this straight. Page A just contains a menu bar, etc. and does a PHP `include` of page B. Page B makes an API call, and based on the API response, it tries to set a `Location:` header that redirects to some content you want to include/display within page A? If that's correct, then can you perhaps have page B fetch the content with [cURL](http://www.php.net/manual/en/function.curl-exec.php) instead of setting the header? A `Location` header is something the user's browser handles, and not your script. – pieman72 May 02 '14 at 06:56

1 Answers1

0

This code work for me, with an "UTF-8 without bump" file encoding.

Ob_start();
Header("Location: " . $url);
Ob_end_flush();

Normally header(); only works above everything else content, but this should prevent the error message you are getting.

Aprilsnar
  • 521
  • 1
  • 5
  • 14