[英]Matching the url based on the page the user is on
I'm trying to right a simple if
statement to basically say that if the user is on page_A then echo "i am on page A";
我试图纠正一个简单的
if
语句,基本上说如果用户在page_A上,则echo "i am on page A";
and if I'm on page_B then echo "i am on the page B";
如果我在page_B上,则
echo "i am on the page B";
and I'm using the PHP function $_SERVER['REQUEST_URI'];
并且我正在使用PHP函数
$_SERVER['REQUEST_URI'];
to check if they match what is in my string that is stored in the variable $page_A
and $page_B
. 检查它们是否匹配存储在变量
$page_A
和$page_B
中的字符串中的$page_B
。
my code is as follows: 我的代码如下:
<?php
$page_A = "/test.co.za/voice/";
$page_B = "/test.co.za/artistes/";
$match = $_SERVER['REQUEST_URI'];
if ( $page_A == $match ) {
echo "i am on page A";
}elseif ( $page_B == $match ) {
echo "i am on the page B";
}
?>
Where am i going wrong or is there another way i can achieve getting this to work? 我在哪里出错了,或者还有另一种方法可以使它正常工作?
Thanks team :) 谢谢团队:)
if(strpos($_SERVER['REQUEST_URI'],'voice')!==false){
echo "i am on page A";
}elseif(strpos($_SERVER['REQUEST_URI'],'artistes')!==false){
echo "i am on the page B";
}
I don't quite understand how you are doing this, if you have 2 different pages you always know at which page you are. 我不太了解您的操作方式,如果您有2个不同的页面,那么您总是知道您在哪一页。
If you are using htaccess to redirect the request to a unique file, you should do something like this: Add this line in htaccess: 如果您使用htaccess将请求重定向到唯一文件,则应执行以下操作:在htaccess中添加以下行:
RewriteRule ^([0-9a-zA-Z-_]*)\/?([0-9a-zA-Z-_]*)\/?([0-9a-zA-Z-_]*)\/?([0-9a-zA-Z-_]*)\/?$ index.php?p=$1&s=$2&d=$3&ID=$4&%{QUERY_STRING}
Now, if you open for instances: http://test.co.za/voice/ this will be redirected to /index.php. 现在,如果您打开实例: http ://test.co.za/voice/,它将被重定向到/index.php。 At index.php you can read:
在index.php上,您可以阅读:
$page = $_REQUEST['p'];
if ($page == 'voice') { //do stuff }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.