为什么如果条件不起作用?$_SERVER['SERVER_NAME'] .$_SERVER['REQUREST_URI'] [英] Why does if condition not working? $_SERVER['SERVER_NAME'] . $_SERVER['REQUREST_URI']
问题描述
我试图在每个网址上显示不同的词.
I am trying to display different word on each url.
$host = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
if($host=="www.thesofacompany.ca/index.php?route=information/contact"){
echo "A";
}
if($host=="www.thesofacompany.ca/index.php?route=information/information&information_id=4") //This if statement isn't working..
{
echo "B";
}
这是我使用过的 if 语句.但是第二个 if 语句不起作用.即使 $host 具有正确的字符串,程序也会跳过第二个 if 语句..
This is the if statement I've used.. But the second if statement is not working. The program skips the second if statement even when $host has the correct strings..
是否有特殊字符 &使它不起作用?
Does special character & makes it not working?
推荐答案
只是猜测,但字符串比较区分大小写,因此如果 url 大小写不正确,它将评估为 false.如果您在 IIS 上托管,这可能是一个问题,因为 IIS 不区分大小写.你可能想试试:
Just a guess, but the string comparison is case sensitive so if the url has incorrect case, it will evaluate to false. If you are hosting on IIS, this can be a problem since IIS is case insensitive. You might want to try :
$host = strtolower($_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']);
if($host=="www.thesofacompany.ca/index.php?route=information/contact"){
echo "A";
}
if($host=="www.thesofacompany.ca/index.php?route=information/information&information_id=4") //This if statement isn't working..
{
echo "B";
}
这将确保您有一个小写字符串进行比较.
This will just make sure you have a lowercase string to compare against.
这篇关于为什么如果条件不起作用?$_SERVER['SERVER_NAME'] .$_SERVER['REQUREST_URI']的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!