简体   繁体   English

PHP-file_get_contents跟随标题刷新

[英]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". 我用另一个使用函数“ file_get_contents”的php文件调用此脚本。 Unfortunately it does not work. 不幸的是,它不起作用。 With header location there aren't problems. 头位置不存在问题。

Any suggestions? 有什么建议么?

-- UPDATES -- - 更新 -

I have followed the advice of Oscargeek. 我听了Oscargeek的建议。 I have updated the code with a print of HTML that contains meta-refresh. 我已经用包含元刷新的HTML打印更新了代码。 The script that call this url, is a "system" of cron, and make this call in a foreach. 调用此URL的脚本是cron的“系统”,并在foreach中进行此调用。 So i think it can't work. 所以我认为这行不通。 I have changed this call with a cron and wget, but the result is the same. 我已经使用cron和wget更改了此调用,但是结果是相同的。

Other suggestion ? 还有其他建议吗?

When you are doing a file_get_contents, you get the HTML but not the headers of the first page. 在执行file_get_contents时,您将获得HTML而不是首页的标题。

file_get_contents only return a string without headers, header location it's working because are doing the redirection before return this string. file_get_contents仅返回不包含标题的字符串,它起作用的标题位置是因为在返回此字符串之前正在执行重定向。

Try to do the redirect from the HTML, in your first page write this content: 尝试从HTML进行重定向,在您的第一页中编写以下内容:

<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. 在要调用的PHP中,只应打印此内容,而不打印其他数据,刷新即可。

Okay, first of all, I'm wondering why you use file_get_contents to include a PHP-File. 好的,首先,我想知道为什么您使用file_get_contents来包含一个PHP文件。 I'd use include or require. 我会使用include或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. 因此,这意味着如果它们已发送,它们是通过您尝试读取的文件发送的-但是:由于该脚本未通过HTTP协议发送,因此不会发送。

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. 如果您想像这样使用它,我建议您使用Oscargeek所述的HTML-Refresh,或者如果要保留PHP代码,则使用Include / Require。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM