Page 1 of 1

Help with if condition

Posted: Mon Oct 31, 2011 1:03 pm
by Logaritmator
I am a beginner in php, and I would like to ask for some help in relating to the installation of a line of code in the header of a php file.

I am working with an OS shop and trying to install a different css file for some of its sections.

CSS are in the head, and the head is in a the template_top.php file.

I would like to set css files for contact.php, product_info.php and some others.

The idea is to set an if condition to detect the page, which would set this line:

<link rel="stylesheet" type="text/css" href="stylesheet-b.css" />

in the head among the other css links.

Is it posible?

Thanks.

Re: Help with if condition

Posted: Mon Oct 31, 2011 4:24 pm
by social_experiment
Yes it's possible

Re: Help with if condition

Posted: Mon Oct 31, 2011 6:05 pm
by Logaritmator
I have tried with this:

Code: Select all

<?php
$url = $_SERVER[''REQUEST_URI'']; 
$base = basename($url);
if($base == "index.php"){
echo <link rel="stylesheet" type="text/css" href="stylesheet-b.css"/>;}
?> 
But it results in a 500 server error

Some clue?

Re: Help with if condition

Posted: Mon Oct 31, 2011 8:12 pm
by twinedev
Well if you really did two single quotes on each side of REQUEST_URI, then yeah, that will error.

Re: Help with if condition

Posted: Mon Oct 31, 2011 11:35 pm
by social_experiment
Wouldn't $_SERVER['PHP_SELF'] by a better option for your script?