English 中文(简体)
如本页所示,
原标题:If this Page Show This Else Show This

除联络网页外,所有网页都希望用墨头显示如下。 php包括:

<p><a href="contact.php">Contact</a></p>

网页contact.php, 我想表明:

<p><a href="index.php">Home</a></p>

这应当纠正吗?

最佳回答
<?php
if (stripos($_SERVER[ REQUEST_URI ],  contact.php )){
     echo  <p><a href="index.php">Home</a></p> ;
}
else{
     echo  <p><a href="contact.php">Contact</a></p> ;
}
问题回答
if ($_SERVER["SCRIPT_NAME"] ==  /contact.php ) {
    echo  <p><a href="index.php">Home</a></p> ;
} else {
    echo  <p><a href="contact.php">Contact</a></p> ;
}

http://www.php.net/manual/en/maind.variables.server.php” rel=“nofollow”$_SERVER[PHP_SELF],其中载有你目前要求的网页名称。 加上basename(。 这一工作应当:

if( basename($_SERVER[ PHP_SELF ],  .php ) ==  contact  ) {
    // Contact page
} else {
    // Some other page
}

快速和 d脏的解决办法是:

<?php
$current_page =  contact ;
include( inc_header.php );
....
?>

In inc_header.php:

<?php
if($current_page ==  contact ) {
    // show home link
} else {
    // show contact link
}
?>

如果发言,你可以简单地这样做,但这只能为你的联络页工作。 您也可在您的 in首档案中使用一种简单的功能,以便:

function LinkToPageOrHome( $script, $title ){
   if ( strtolower( $_SERVER[  SCRIPT_NAME  ] ) == strtolower( $script) ){
       $script =  home.php ;
       $title =  Home ;
   }
   echo  <p><a href="  . $script.  ">  . htmlentities( $title ) .  </a></p> ;
}

从设计角度看,它是一种unt法,但你可以使用LinkToPageOrHome(网页.php, 我的英文版);





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...