Jump to content

Help with ['PHP_SELF']


mdonders

Recommended Posts

Hello.

 

I am having a bit of problem thinking this one out and I am looking for your help.

I am using a CSS template on my website and am looking to have the current page's link have a background behind it so the user knows what page they are on.

 

I figured that if I used ['PHP_SELF'] with an if statement I could just say something to the effect of if ['PHP_SELF'] = index.php then <li class=active><a href="index.php">Home</a> and endif

 

I for some reason cannot figure out how to put the whole code together.

 

Your help is greatly appreciated!

Link to comment
https://forums.phpfreaks.com/topic/63551-help-with-php_self/
Share on other sites

are you trying to call this inside a separate CSS file, or inside the php page itself?

 

if youre calling it from a separate CSS page, then its not going to be executed since by default, only accepted file extensions are interpreted server side.

 

you could write a css.php page that has the CSS info, include the page on yours, then it will execute the code and echo out the CSS code (you need to be careful to have it echo at the right location).

Link to comment
https://forums.phpfreaks.com/topic/63551-help-with-php_self/#findComment-316710
Share on other sites

try this...

 

<head>
  <?php if ($_SERVER['PHP_SELF'] == "index.php"){ ?>
         <link href="styleindex.css" rel="stylesheet" type="text/css" />
  <?php } else if ($_SERVER['PHP_SELF'] == "about.php"){ ?>
         <link href="styleabout.css" rel="stylesheet" type="text/css" />
  <?php } ?>
</head>

 

this is the header for the page.

Link to comment
https://forums.phpfreaks.com/topic/63551-help-with-php_self/#findComment-317501
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.