简体   繁体   English

同一页中两个不同网址的标头(PHP)

[英]Two headers for different url's in the same page (PHP)

I want to, once the user has arrived the page, first, download an item using another script and then, redirect him or her to the index. 我想在用户到达页面后首先使用另一个脚本下载项目,然后将其重定向到索引。

So I have the following code: 所以我有以下代码:

$filename = $_GET["file"];

$down = 'components/com_djclassifieds/views/item/tmpl/download.php?file='.$filename;

header( "refresh:2;url=$down" );   

header( "refresh:5;url=index.php" );

And, for example, the following url: 并且,例如,以下URL:

http://my.web.com/index.php?option=com_k2&view=item&layout=item&id=39&file=test.pdf http://my.web.com/index.php?option=com_k2&view=item&layout=item&id=39&file=test.pdf

But it is not working. 但这是行不通的。 I also tried to use 'Location' in this code: 我也尝试在此代码中使用“位置”:

$filename = $_GET["file"];

header('Location: http://'.$_SERVER['HTTP_HOST'].str_replace(basename($_SERVER['PHP_SELF']), '', $_SERVER['PHP_SELF']).'/components/com_djclassifieds/views/item/tmpl/download.php?file='.$filename);

exit;

header( "refresh:5;url=index.php" );

And it downloads the file but after that it does not redirect me to the index. 并下载文件,但此后它不会将我重定向到索引。

What am I doing wrong? 我究竟做错了什么?

Don't bother with the PHP. 不要打扰PHP。 You can do it with JQuery. 您可以使用JQuery做到这一点。

HTML: HTML:

<script src="code.jquery.com/jquery.min.js"></script>
<div style='display:none;' id="div"></div>
<script>
var iframe = $("<iframe/>").attr({
    src: "http://example.com/path/file.extension"
}).appendTo($("#div"));
window.location="http://example.com/path/redirect.html"
</script>

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

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