重定向到 2 个页面 [英] Redirect to 2 pages

查看:43
本文介绍了重定向到 2 个页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 PHP 页面,我想先将它重定向到一个页面(例如 google.com),然后再重定向到另一个页面(例如 bing.com).

I have a PHP page and I want to redirect it first to a page (eg google.com) then to another page (eg bing.com).

为此,我使用了以下内容:

To do this I'm using the following:

header('Location: http://google.com');
header('Location: http://bing.com');

问题在于脚本在第一个标题"处停止.有没有办法做到这一点?

The problem is that the script stops at the first 'header'. Is there a way to make this?

推荐答案

恐怕您所描述的行为是不可能的.您究竟希望这如何工作?一个浏览器窗口如何同时进入两个页面?毕竟,浏览器在收到响应之前无法解释您的响应标头.因此,您显示的两行代码之间没有任何步骤,浏览器会在同一响应中接收它们.

I'm afraid the behavior as you've described it isn't possible. Exactly how would you expect this to work? How can a single browser window go to two pages at the same time? After all, the browser can't interpret your response headers until it receives the response. So there's no step in between the two lines of code you show, the browser receives them both in the same response.

考虑网络的请求/响应性质,重新考虑您正在尝试做什么以满足您正在解决的需求.你说:

Thinking in terms of the request/response nature of the web, re-consider what you're trying to do in order to meet the need you're addressing. You stated that:

我想先将它重定向到一个页面(例如 google.com),然后再重定向到另一个页面(例如 bing.com)

I want to redirect it first to a page (eg google.com) then to another page (eg bing.com)

那里有一个事件顺序:

  1. 用户请求您的页面.
  2. 您的页面响应重定向到第 1 页.
  3. 用户请求页面 1.
  4. 第 1 页响应.
  5. 用户请求第 2 页.
  6. 第 2 页响应.

您要插入的步骤在上面的 4 到 5 之间.自然地,您无法修改或以任何方式控制 Google 的响应,因此您无法通过重定向到页面 2 来控制您无法控制的页面 1.(事实上,即使他们这样做了,它要么是内容,要么是重定向...不是两个.)

The step where you're looking to interject is between 4 and 5 above. Naturally, you can't modify or in any way control Google's response so you can't have a Page 1 that you don't control respond with a redirect to Page 2. (Indeed, even if they did, it's either content or a redirect... not both.)

在我的脑海中,可能有一种可能适合您需求的解决方法.您可以使用框架将用户留在您的页面上,同时向他们显示这些其他页面的内容.在您可以控制的父框架中,您可以使用 JavaScript 设置各种计时器和其他事件,这些计时器和其他事件会将用户从第 1 页引导到第 2 页.(它是即时的吗?如果是这样,为什么还要为第 1 页而烦恼?是过了一会儿吗?应该是什么导致从第 1 页重定向到第 2 页?)

Off the top of my head there may be a workaround that might fit your needs. You could use frames to keep the user on your page while showing them the content of these other pages. Within your parent frame, which you would control, you can use JavaScript to set the various timers and other events which would direct the user from Page 1 to Page 2. (Is it instant? If so, why bother with Page 1 at all? Is it after a few moments? What should cause the redirect from Page 1 to Page 2?)

这篇关于重定向到 2 个页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆