Reputation: 448
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";
and if I'm on page_B then echo "i am on the page B";
and I'm using the PHP function $_SERVER['REQUEST_URI'];
to check if they match what is in my string that is stored in the variable $page_A
and $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 :)
Upvotes: 0
Views: 35
Reputation: 51
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";
}
Upvotes: 1
Reputation: 4065
I don't quite understand how you are doing this, if you have 2 different pages you always know at which page you are.
If you are using htaccess to redirect the request to a unique file, you should do something like this: Add this line in 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. At index.php you can read:
$page = $_REQUEST['p'];
if ($page == 'voice') { //do stuff }
Upvotes: 0