PHP 中跳转到另一个页面

发布于 2024-11-18 06:19:57 字数 333 浏览 2 评论 0原文

我很想知道除了使用 javascript 之外是否还有其他方法使 php 转到另一个页面?

因为 head 仅在第一个被调用的函数时才起作用,所以我求助于 javascript 来转到另一个页面。但是php一定有类似的功能不是吗?

    <?php session_start();
      session_destroy();
      echo '<script language="JavaScript">
<!--
 window.location="home.php";
//-->
</script>';



?>

I was curious to know if there was another way than using javascript to make php go to another page ?

Because head only works when it is the first function to be called, so I resorted to javascript to go to another page. But php must have a similar function no ?

    <?php session_start();
      session_destroy();
      echo '<script language="JavaScript">
<!--
 window.location="home.php";
//-->
</script>';



?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

神回复 2024-11-25 06:19:57

你有一个错误。

header('Location: some_location.php');

需要是第一个输出的东西,这意味着,如果您回显在此之前的任何内容,它将不起作用,否则它将起作用。

所以只是:

header('Location: some_location.php');

You have a mistake.

header('Location: some_location.php');

Needs to be the first things that's being output, meaning, if you echo anything before this, it wont work, other wise it will work.

So just:

header('Location: some_location.php');
深爱不及久伴 2024-11-25 06:19:57

尝试

<?php 
    header('Location: error.php');
?>

了解更多信息:php 手动标头函数

Cleber。

Try

<?php 
    header('Location: error.php');
?>

For more info: php manual header function

Cleber.

长亭外,古道边 2024-11-25 06:19:57

您需要使用 php

http://www 中的函数标头修改 HTTP 响应的标头.php.net/manual/function.header.php

<?php
header("Location: home.php")
?>

您还可以添加浏览器使用的特定标头。
例如,如果您的页面已永久移动,您可以使用:

<?php
header('HTTP/1.1 301 Moved Permanently');
header("Location: home.php");
?>

您可以在以下位置查看有关重定向的更多信息: http:// /en.wikipedia.org/wiki/URL_redirection

You need to modify the header of your HTTP Response with the function header in php

http://www.php.net/manual/function.header.php

<?php
header("Location: home.php")
?>

Also you can add a particular header used by the browser.
for example if your page has moved permanently, you can use:

<?php
header('HTTP/1.1 301 Moved Permanently');
header("Location: home.php");
?>

You can see more information about redirection on: http://en.wikipedia.org/wiki/URL_redirection

深居我梦 2024-11-25 06:19:57

当然。您可以使用“元重定向”:

http://webdesign.about.com/ od/metataglibraries/a/aa080300a.htm

例如:
<代码>

<meta http-equiv="refresh" content="2;url=http://webdesign.about.com/"> 

Sure. You can use a "meta redirect":

http://webdesign.about.com/od/metataglibraries/a/aa080300a.htm

For example:

<meta http-equiv="refresh" content="2;url=http://webdesign.about.com/"> 

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文