开发者

Question about including html page in PHP

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:开发者_如何学Python


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!


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" />


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" /> 


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜