在php中浏览页面

时间:2012-06-07 15:30:43

标签: php navigation

所以我一直在google上阅读,这只是一堆不同的答案,没有多少解释。

我的问题是如何在PHP页面之间切换?假设我的服务器上有一个目录,其中包含以下文件:

index.php
about_us.php
contact_us.php

假设在所有3个页面上,我有一个包含3个链接的标题:

Home
Info
Contact

当其中一个按钮(让我们说接触)被击中时会发生什么?

我已经阅读了3种技术:

Php: header("contact_us.php")
javascript: window.location = "contact_us.php";
html: <meta http-equiv="Refresh" content="5; URL="contact_us.php">

今天的标准是否优先考虑这些?我在某处读到你不应该使用php的header()函数。

任何见解都会非常有助于我做出决定:)

7 个答案:

答案 0 :(得分:10)

只需将它们定为常规链接

即可
<a href="contact_us.php">Contact</a>

答案 1 :(得分:2)

只需使用html超级引用...

<a href="index.php">Home</a> <a href="contact_us.php">Contact Us</a> <a href="about_us.php">About Us</a>

答案 2 :(得分:2)

你只需要像

那样建立链接
<a href="contact_us.php">Contact Us</a>

并且无论何时点击链接,他们都将被带到该页面。如果您不熟悉PHP:您可以用PHP编写HTML。

答案 3 :(得分:2)

您也可以使用此技术:(不需要数据库)

假设你有一个index.php文件:

<?php
$mypage = $_GET['mypage'];
switch($mypage)
{
case "one":
    @include("one.php");
    break;

case "two":
    @include("two.php");
    break;

default:
    @include("default.php");
}
?>

然后引用如下:

<a href="index.php?mypage=one">one</a>

And:

<a href="index.php?mypage=two">two</a>

直接调用index.php会带您进入default.php页面内容。

答案 4 :(得分:0)

你应该直接调用脚本,或者有一个调用它的处理程序(如果你想要好的URL)。

<a href="/contact_us.php">Contact</a>

你不应该使用任何类型的重定向,它会对SEO产生不良影响。

答案 5 :(得分:0)

正如其他人所说,你只需要使用常规的html来建立链接。

您指的是重定向方法,它会在没有用户交互的情况下更改当前位置。如果您想这样做,使用PHP的header()发送HTTP标头绝对是首选方法。

答案 6 :(得分:-1)

我只有解决方案:)

<html>
<body>
<button onclick="confirmNav() ? (doubleConfirmNav() ? navigate() : cancelled() ): cancelled();">Contact Us</button>


<script type="text/javascript">

function confirmNav() {
    var r=confirm("Do you really want to navigate to 'Contact Us'?");
    if (r==true) {
      return true;
    } else {
      return false;
    }
}

function doubleConfirmNav() {
    var r=confirm("Are you 100% sure?");
    if (r==true) {
      return true;
    } else {
      return false;
    }
}

function cancelled() {
    alert("cancelling navigation");   
}

function navigate() {
    // purposely delay the redirect to give the image of a high traffic site
     setTimeout(function() {   
         window.location = "contact_us.php";
     }, 5000);   
 }

</script>

</body>
</html>
相关问题