Help with if condition

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Logaritmator
Forum Newbie
Posts: 2
Joined: Mon Oct 31, 2011 12:55 pm

Help with if condition

Post 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.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Help with if condition

Post by social_experiment »

Yes it's possible
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Logaritmator
Forum Newbie
Posts: 2
Joined: Mon Oct 31, 2011 12:55 pm

Re: Help with if condition

Post 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?
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: Help with if condition

Post by twinedev »

Well if you really did two single quotes on each side of REQUEST_URI, then yeah, that will error.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Help with if condition

Post by social_experiment »

Wouldn't $_SERVER['PHP_SELF'] by a better option for your script?
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply