Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8430323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:34:31+00:00 2026-06-10T05:34:31+00:00

How to write the following in PHP: IF current page’s name is pagex.php THEN

  • 0

How to write the following in PHP:

IF current page’s name is pagex.php
THEN please load these additional CSS rules:
#DIVS { color:#FFF }
IF current page’s name is anotherpage.php
THEN please load following CSS rules:
#DIVS { color: #000 }

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T05:34:31+00:00Added an answer on June 10, 2026 at 5:34 am

    PHP has some “magic constants” that you can inspect to get this information. Take a look at the ` __FILE__ constant.

    The full path and filename of the file. If used inside an include, the name of the included file is returned. Since PHP 4.0.2, FILE always contains an absolute path with symlinks resolved whereas in older versions it contained relative path under some circumstances.

    So you can take this __FILE__ variable and execute the basename() function on it to get the file name. The basename() function returns the trailing name component of a path. Then you simply do a switch case to match the desired value –

    $fileName = basename(__FILE__);
    switch($fileName){
      case 'pagex.php':
        echo '<link .... src="some_stylesheet_file.css" />';
        break;
      case 'anotherpage.php':
        echo '<link .... src="another_stylesheet_file.css" />';
        break;
    }
    

    Your additional CSS rules can sit within those separate files.

    Alternatively, if you don’t want to split your css into multiple files, you can echo those specific rules into your page’s head element like this –

    echo '<style type="text/css">';
    $fileName = basename(__FILE__);
    switch($fileName){
      case 'pagex.php':
        echo '#DIVS { color:#FFF }';
        break;
      case 'anotherpage.php':
        echo '#DIVS { color: #000 }';
        break;
    } 
    echo '</style>';
    

    References –

    • basename()
    • php magic constants
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use the following to load a new page within the current page, no
I am wondering if you were to write the following Codeigniter PHP code: $this->load->library('form_validation');
In my .htaccess file i have the following re-write rule RewriteRule ^([a-z]*)$ work.php?album=$1 [L]
I wrote the following snippet in order to handle errors. (Page.php gets included in
I want to upload an image in Zend-framework. In Application_Form_Test.php I write following code....
I am working on creating page links from DB like the following example. Current
In PHP, you can write the following: date_default_timezone_set(UTC); How do I do I write
i wrote in file showList.php the following form, which select items from the database
How to write following statement in c using switch statement in c int i
I wanted to write following query through codeigniter's db helper class, guide me plz

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.