Max
Max

Reputation: 1

PHP - file_get_contents follow header refresh

I have a script that use the

header('Refresh: 5; url=http..');
die();

And i call this script with another php file that use the function "file_get_contents". Unfortunately it does not work. With header location there aren't problems.

Any suggestions?

-- UPDATES --

I have followed the advice of Oscargeek. I have updated the code with a print of HTML that contains meta-refresh. The script that call this url, is a "system" of cron, and make this call in a foreach. So i think it can't work. I have changed this call with a cron and wget, but the result is the same.

Other suggestion ?

Upvotes: 0

Views: 1332

Answers (2)

Oscar Lidenbrock
Oscar Lidenbrock

Reputation: 816

When you are doing a file_get_contents, you get the HTML but not the headers of the first page.

file_get_contents only return a string without headers, header location it's working because are doing the redirection before return this string.

Try to do the redirect from the HTML, in your first page write this content:

<html>
    <head>
        <meta http-equiv="refresh" content="5; url=http://google.com" />
    </head>
</html>

In the PHP that you are calling, you should only print this content without other data and the refresh will do.

Upvotes: 1

SophieXLove64
SophieXLove64

Reputation: 316

Okay, first of all, I'm wondering why you use file_get_contents to include a PHP-File. I'd use include or require.

For your problem some additional information:

The problem is: None of those headers ever was running in your other script. So this means IF they are send, they got send by the file you were trying to read - but: Since the script didn't got send via HTTP-Protocol, it doesn't send.

If you want to use it like this, I'd advice you to use HTML-Refresh like Oscargeek stated, or use Include / Require, if you want to keep PHP-Code.

Upvotes: 0

Related Questions