View Full Version : PHP Include real newbee
stevehendo34
07-21-2010, 07:10 PM
How can I use php to load code from an external html file (external.html)
Want it to run instead of were "Test insert text is in table"
<tr>
<td class="bgy" background="images/t4.gif" height="100%"
valign="top"><br>
Test insert text in table<br>
</td>
</tr>
<tr>
this dose not work why?
<tr>
<td class="bgy" background="images/t4.gif" height="100%"
valign="top"><br>
<?php
include ("http://locaalhost/external.html");
?>
</td>
</tr>
<tr>
external.html
<html>
<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
<title>external</title>
</head>
<body>
external_page
</body>
</html>
this dose not work why?
<tr>
<td class="bgy" background="images/t4.gif" height="100%"
valign="top"><br>
<?php
include ("http://locaalhost/external.html");
?>
</td>
</tr>
<tr>
There may be any number of reasons it doesn't work.
>> is the filename/path correct (did you misspell "localhost" in your script, as you did in your example above)?
>> is your page saved as a .php file?
>> is your computer set up to run php scripts (e.g., using xampp or other server software)?
No way for us to know for sure, without knowing more about what's going on.
external.html
<html>
<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
<title>external</title>
</head>
<body>
external_page
</body>
</html>
Also,
If you're including an html page inside another, it should only have the content you want included - not its own <head>, <body>, etc. That will result in messy markup that could generate errors, or at least, not display the way you want it:
<html>
<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
<title>main page</title>
</head>
<body>
<!--this is the included page-->
<html>
<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
<title>external</title>
</head>
<body>
external_page content
</body>
</html>
<!--as you can see, you now have two head sections, etc., nested inside each other,
when all you really wanted was the *content* of the external page-->
</body>
</html>
fastsol1
07-21-2010, 07:42 PM
You have to make sure the file you are trying to include to is a php file. The included file can be html if you want. Then just put this code where you want the include and make sure you make the path to the file correct like includes/include.html or just include.html
<?php include ('include.html'); ?>
stevehendo34
07-21-2010, 08:19 PM
"is your page saved as a .php file?"
"You have to make sure the file you are trying to include to is a php file"
Are you saying external.htm has to have a .php extention
Exact code:
<tbody>
<tr>
<td height="100%" valign="top" width="1"><br></td>
<td height="100%" valign="top"><?php include ('http://localhost/external.htm');?></td>
</tr>
</tbody>
</table>
</td>
<td valign="top" width="1"><img src="images/t4-r.gif"
height="187" width="6"></td>
</tr>
</tbody>
external.htm content
<html>
<head>
<title></title>
</head>
<body>
<p>external_page / paragraph to show up via php include above
</body>
</html>
no, the file that is using the include (the file where "include('external.html');" is written) needs to use the .php extension.
Do you have a server installed locally? If so, are any errors being generated (shown) when you run your script?
You might also use a relative path (just "external.htm" if both files are in the same folder) instead of using the http:// address.
stevehendo34
07-21-2010, 09:13 PM
"no, the file that is using the include (the file where "include('external.html');" is written) needs to use the .php extension."
got ya--Im sure this what I need to do
I am not a programmer @ all just starting on PHP kinda know HTML
"you might also use a relative path (just "external.htm" if both files are in the same folder) instead of using the http:// address."
Ok I was floundering and tried both.
what is the name of the main file, including the extension (this one):
<tbody>
<tr>
<td height="100%" valign="top" width="1"><br></td>
<td height="100%" valign="top"><?php include ('http://localhost/external.htm');?></td>
</tr>
</tbody>
</table>
</td>
<td valign="top" width="1"><img src="images/t4-r.gif"
height="187" width="6"></td>
</tr>
</tbody>
djr33
07-22-2010, 01:53 AM
You might also use a relative path (just "external.htm" if both files are in the same folder) instead of using the http:// address.
I believe this is likely the problem: some settings in PHP disallow including files from other websites and if you refer to your page using "http..." then this is just like loading a page from another site. You must use the relative path to the file like has been explained above.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.