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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.