• 0

Including CSS in php?


Question

How do you include a css file in a php file? I tried use include for the css file but it always comes out as text. But since the css has been included in the php files include file it still should work the same way? (If you still don't get it then look at it this way: test.php-> include "body.html" -> body.html (contains the css file))

Here's how it looks like: http://lacydic.com/test.php.'>http://lacydic.com/test.php.

And here's how its supposed to look like: http://lacydic.com/

Link to comment
Share on other sites

6 answers to this question

Recommended Posts

  • 0

CSS should always be inserted into:

 
 <head>
 </head>

You cannot include a CSS file using PHP. If anything you can create "header.php" and include that file as necessary. However, stylesheets should never be included.

Using your own test.php as an example:

This snippet would be header.php:

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><? if (isset($subtitle)) { echo $subtitle; } ?></title>
<link href="../style.css" rel="stylesheet" type="text/css" />
<link rel="shortcut icon" type="image/x-icon" href="../favicon.ico">
</head>

<body>

This snippet would be test.php:

 
<?
$subtitle = "Example Title";
include('header.php');
?>

<div id="content">Whatever content you have goes here</div>

<?
include('footer.php');
?>

PS - You already "include" stylesheets when you utilize:

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

Link to comment
Share on other sites

  • 0

I did as you told to insert the code snippet into header2.php:

/header2.php

<?php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><? if (isset($subtitle)) { echo $subtitle; } ?></title>
<link href="../style.css" rel="stylesheet" type="text/css" />
<link rel="shortcut icon" type="image/x-icon" href="../favicon.ico">
</head>

<body>

?>

In test.php:

<?php
include "header.php";
include "body.php";
include "footer.php";
include "news.php";
include "header2.php";
?>

But I still get the page without the css file.

Link to comment
Share on other sites

  • 0

Why is the header2 file at the end? Why do you have 2 headers? Go to test.php in your browser and have a look at your source code and see what it's outputting.

You've got 5 <html> tags...

Think of includes as parts of a whole, you don't put <html><head><body> etc in every one of your include files.

Link to comment
Share on other sites

  • 0

I'm not sure you understand, or I'm not understanding you, your files should look something like this:

header.php

&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; 
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; 
&lt;head&gt; 
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt; 
&lt;title&gt;Untitled Document&lt;/title&gt; 
&lt;link href="../style.css" rel="stylesheet" type="text/css" /&gt; 
&lt;link rel="shortcut icon" type="image/x-icon" href="../favicon.ico"&gt; 
&lt;/head&gt; 

&lt;body&gt; 

top.php

&lt;div id="body2"&gt; 

&lt;div id="headWrap"&gt; 
&lt;div id="topPan"&gt; 
	&lt;a href="../index.html"&gt;&lt;img src="../images/logo.gif" alt="LaCydic.com" border="0" class="logo" title="LaCydic.com" /&gt;&lt;/a&gt; 
	&lt;/div&gt; 
    &lt;/div&gt; 
   &lt;!--wrapper.a7--&gt; &lt;div id="body3"&gt; 
		&lt;ul class="menu red"&gt; 
	&lt;li&gt;&lt;a href="http://blog.lacydic.com/" title=""&gt;Blog&lt;/a&gt;&lt;/li&gt; 
	&lt;li class="current"&gt;&lt;a href="http://dl.lacydic.com" title=""&gt;Download&lt;/a&gt;&lt;/li&gt; 
	&lt;li&gt;&lt;a href="/features" title="" &gt;Features&lt;/a&gt;&lt;/li&gt; 
	&lt;li&gt;&lt;a href="/about.php" title=""&gt;About Us&lt;/a&gt;&lt;/li&gt; 
	&lt;li&gt;&lt;a href="/contact.php" title=""&gt;Contact Us&lt;/a&gt;&lt;/li&gt; 
    	&lt;li&gt;&lt;a href="/forum" title=""&gt;Forum&lt;/a&gt;&lt;/li&gt; 
        	&lt;li&gt;&lt;a href="/tos.php" title=""&gt;ToS&lt;/a&gt;&lt;/li&gt; 

body.php

&lt;div id="tableLeft"&gt; 
&lt;h2 class="tabletext2"&gt;Latest Blog Updates: &lt;/h2&gt; 
&lt;p class="tabletext"&gt; 
&lt;strong&gt;What is it?&lt;/strong&gt;&lt;/p&gt; 
&lt;p class="tabletext"&gt; LaCydic is a website that serves as a purpose for educational use on http bypassing. &lt;/p&gt; 
&lt;/div&gt; 

&lt;div id="tableRight"&gt; 
&lt;h2 class="tabletext2"&gt; CHANGELOG:&lt;/h2&gt; 
&lt;p class="tabletext"&gt; 
2.0.0.1 - Fixed some links but some links might not work until &lt;br /&gt; 
 private beta. &lt;br /&gt; 
  2.0.0.0 - Added a whole new design and a whole new system. &lt;br /&gt; 
  1.4.0.3 - Added a features page and a registeration page &lt;/p&gt; 
&lt;/div&gt; 

&lt;/div&gt; 
&lt;/td&gt; 
  &lt;/tr&gt; 
  &lt;tr&gt; 
    &lt;td&gt;&lt;div id="blackboxa7"&gt; 
Coming Soon!
&lt;/div&gt;    &lt;/td&gt; 
  &lt;/tr&gt; 
&lt;/table&gt; 

copyright.php

&lt;div id="footermainPan"&gt; 
  &lt;div id="footerPan"&gt; 

		&lt;p class="copyright"&gt;©2010 LaCydic.com All right reserved.&lt;br /&gt;| Designed by &lt;a href="http://astronomy7.com/portfolio"&gt;Astronomy7.com&lt;/a&gt; |&lt;/p&gt; 

  &lt;/div&gt; 
&lt;/div&gt;

newsfooter.php

&lt;table width="100%" border="0" cellspacing="1" cellpadding="1"&gt; 
&lt;tr&gt;&lt;td&gt;&lt;div id="marquee"&gt;&lt;strong&gt;Update:&lt;/strong&gt;  
         &lt;marquee direction="right" width="80%"&gt; 
LaCydic v3
&lt;/marquee&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt; 
&lt;/body&gt; 
&lt;/html&gt; 

See how they are not all complete html pages, but when you join them it becomes a complete html page?

So test.php will be:

&lt;?php
include "header.php";
include "top.php";
include "body.php";
include "copyright.php";
include "newsfooter.php";
?&gt;

(There are also a lot of HTML errors such as tags not being closed.)

Apart from that, the CSS file is loading fine.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.