Viewed   98 times

I was wondering wether there is a way to include some html content inside another html using only html?

A replacement to PHP's

<?php include("file.php"); ?>

Is this possible?


This has brought up some confusion, what I needed was "almost an html tag" that had the functionality of including a html document in another.



It cannot be done purely by HTML. (There are iframes, however, but I don't think that qualifies in this case.)

It can be done using JavaScript. You get the other file via Ajax, and place its contents inside an HTML element on the current page.

Thursday, August 18, 2022

Try using this:

AddHandler x-httpd-php5-cgi .html

See here:

Friday, September 2, 2022

You can download the file contents into a php file then include that,

$url = "";
$file = file_get_contents($url);
file_put_contents('index.php', $file);
include index.php;

I'd recommend changing the name from index.php tho, and make sure the php file isn't being parsed first when you getting it.

There is also nothing safe about this.

Edit: Another option,

There is a php.ini option called allow_url_include.

Friday, October 14, 2022

After some more research I found out what was wrong myself. The problem is in the fact that <?php is a "short opening tag" and so will only work if short_open_tag is set to 1 (in php.ini or something to the same effect). The correct full tag is <?php, which has a space after the second p.

As such the proper equivalent of the include is:

eval('?>' . file_get_contents('external.php') . '<?php ');

Alternatively, you can leave the opening tag out all together (as noted in the comments below):

eval('?>' . file_get_contents('external.php'));

My original solution was to add a semicolon, which also works, but looks a lot less clean if you ask me:

eval('?>' . file_get_contents('external.php') . '<?php;');
Tuesday, December 27, 2022

The issue ending up being a bug with how the server parsed the HTML and with HTML5 tags. For whatever reason, when I added one extra tag set to the SSI, it worked.

My original include looked like this:

    <!--#Include File="/includes/header.shtm"-->

with the included file being:

    <li><a href="#">Home</a></li>
    <li><a href="#">Products</a></li>
    <li><a href="#">About</a></li>
    <li><a href="#">Contact</a></li>

But when I took all of the HTML5 tags out of the include, as shown below, everything worked as normal. I'm not sure if this is an issue with an old version of apache or what, but doing this fixed everything.

    <!--#Include File="/includes/header.shtm"-->
Sunday, November 6, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :