views:

85

answers:

3

Hi,

If I include an HTML page on a PHP page (say, index.php) with the following:

<?php
include ("../../forms/login/form.html");
?>

Then will form.php show up correctly in index.php? When I say correctly, I mean with all of its images and CSS.

The reason I am asking is because that's not the case with me. I tried it out, and it will show the form.html but without any styling...

Any help would be appreciated, thanks!

UPDATE:


Currently, I have the following on forms.html:

<link href="view.css" media="all" rel="stylesheet" type="text/css" />
<script src="view.js" type="text/javascript"></script>
<link href="../../css/style.css" rel="stylesheet" type="text/css" />

Now, forms.html displays correctly by itself.

On index.php, I have:

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>UofS :: Residence Life Management System</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />

</head>

<body>

<?php
include ("html/header.html");
?>

<?php
include ("php/navigation.php");
?>
<br></br>
<?php
include ("forms/login/form.html");
?>
<br></br>
<?php
include ("html/footer.html");
?>

</body>

</html>

The only reference to forms.html is through the php include(). There is no stylesheet pointing to it. This is the page that does not load forms.html correctly. Is this not right?

Thanks!

+6  A: 

The path to your style sheet is probably relative. It will need to be relative to the url in the browser (index.php). Or make it an absolute path.

Edit since your update: view.css and view.js will not be loaded because their paths are relative. Make those paths absolute or relative from the index.php page. Making them absolute will make them work whenever form.html is included from anywhere. Making the paths relative from index.php will make them work when included from there, but not when included from other directories.

Better yet, if you know you need to load those files, put the links on the index.php page and not the form.html page.

Also note that you can use paths that start with the root of your site, you do not have to include the host and domain name:

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

The slash before "css/style.css" will make that an absolute path that will work on your live and dev servers.

Edit...

Assuming that your index.php file is at the root level, try this in forms.html:

<link href="/forms/login/view.css" media="all" rel="stylesheet" type="text/css" />
<script src="/forms/login/view.js" type="text/javascript"></script>
<link href="/css/style.css" rel="stylesheet" type="text/css" />
Scott Saunders
Scott:Thanks for you help. I guess what's confusing me is how I would make the paths absolute (or relative) from the index.php page...Right now, the only reference to forms.html is the php include statements. Can you offer me an example?
behrk2
You need to think of the paths from the point of view of the browser. It's the browser that will interpret them and try to load the css and js files. So make your paths the path from index.php (which the browser loaded) not from forms.html (which the browser never accessed directly). I'll update my answer with some guesses about your directory structure.
Scott Saunders
Thanks again for your help. My index.php is indeed at the root structure, however the code you suggested above made no difference. Hm...
behrk2
I've got it working, now, I just removed the forward slashes from "/forms" and "/css". Thanks!
behrk2
A: 

It will include the HTML file verbatim in the PHP page. If the paths on external resources are correct based on the URL of the PHP page then they will show up.

Ignacio Vazquez-Abrams
+3  A: 

show the form.html but without any styling...

You'll need to adjust the reference to the CSS file accordingly. Probably a better idea to use absolute path.

IF BEFORE

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

NOW:

<link rel="stylesheet" type="text/css" href="http://host/path/to/style.css" /> 
Yada
Thanks for your help, can you check out my updated post?
behrk2
I'd keep the `http://host` part out of it so I can run the same code on my dev and live servers, both other than that, using absolute paths would be the easiest solution.
Wim