Jump to content

elseif issue


jarvis

Recommended Posts

Hi,

 

Am probably being thick (not enough coffee yet!!!). Why is the below not working:

$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
$filename = basename($pageURL);
echo $filename; //debug

if ($filename == 'index.php') {
	echo 'home';
} elseif ($filename == 'about.php') {
	echo 'about';
} elseif ($filename == 'services.php') {
	echo 'services';
} elseif ($filename == 'affiliate.php') {
	echo 'affiliate';
} elseif ($filename == 'links.php') {
	echo 'links';
} else($filename == 'contact.php') {
	echo 'contact';
}

 

The idea is it get the filename from the URL and depending which page, a different image will be shown.

 

Sorry it's a silly question. Your help is appreciated!

 

Many thanks

Link to comment
https://forums.phpfreaks.com/topic/188555-elseif-issue/
Share on other sites

Sorry to sound daft, but if

$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];	
$filename = basename($pageURL);	
echo $filename; //debug

Can give me the filename, then don't I just need to say if filename = $filename, then show x y or z?

As $filename would be links.php, so don't I just need to say, it $filename is equal to links.php show whatever?

Link to comment
https://forums.phpfreaks.com/topic/188555-elseif-issue/#findComment-995465
Share on other sites

Solved:

$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
$filename = basename($pageURL);
#echo $filename; //debug

if ($filename == 'index.php') {
	echo 'home';
} elseif ($filename == 'about.php') {
	echo 'about';
} elseif ($filename == 'services.php') {
	echo 'services';
} elseif ($filename == 'affiliate.php') {
	echo 'affiliate';
} elseif ($filename == 'links.php') {
	echo 'links';
} else {
	echo 'contact';
}

Link to comment
https://forums.phpfreaks.com/topic/188555-elseif-issue/#findComment-995469
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.