Closed Thread Icon

Preserved Topic: Ack... including a php (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=12502" title="Pages that link to Preserved Topic: Ack... including a php (Page 1 of 1)" rel="nofollow" >Preserved Topic: Ack... including a php <span class="small">(Page 1 of 1)</span>\

 
Red Ninja
Bipolar (III) Inmate

From: Detroit, MI US
Insane since: Mar 2001

posted posted 11-05-2002 00:27

I was wondering if there would be a way for me to include php files in an html file without saving the html file with an extension of .htm or .html.

Actually, if there was simply a way to be able to write a small line of php inside an html file and not need to save it as a .php file, that is all I really need. I am skeptical of that. <edit>(sp?)Skeptical</edit>

A client that is outsourcing me feels that this absolutely has to be done this way, but they know very little about code, much less how to actually do it. I don't want to make any waves, so I don't want to tell them that it can't be done until I know for sure (because what if they found out later that it could? I don't like eggs).



[This message has been edited by Red Ninja (edited 11-05-2002).]

mobrul
Bipolar (III) Inmate

From:
Insane since: Aug 2000

posted posted 11-05-2002 00:55

I think you can tell your server to parse any type files as anything.

Upside: idiot client gets his/her way
Downside: your server spends 15 million times longer trying to parse pages as php that don't need to be

Your choice.

For apache and php, open your httpd.conf file.
Scroll down to the lines

code:
# AddType allows you to tweak mime.types without actually editing it, or to
# make certain files to be certain types.
#
# For example, the PHP3 module (not part of the Apache distribution)
# will typically use:
#
#AddType application/x-httpd-php3 .phtml
#AddType application/x-httpd-php3-source .phps

AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps



then add .htm or .html to AddType list so it looks like this:

code:
AddType application/x-httpd-php .php .phtml .html .htm





Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 11-05-2002 01:18

Keep in mind that if you do this, there are security issues to think of: any place a user can add HTML to a page (like a forum or something) might let them put PHP in there. Ads might also be a concern. So think carefully of all the possible abuses.

Lurch
Paranoid (IV) Inmate

From: Behind the Wheel
Insane since: Jan 2002

posted posted 11-05-2002 01:19

that's what i was going to say... i've done that on my own local server and it worked fine...

--Lurch--

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 11-05-2002 04:11

You should be able to use a normal virtual include to do this though it will depend on your server configuration.

<!--#include virtual="/pathtophpfile/file.php" -->

It's kinda dumb but it works. If you are not going to have the php file output dynamic data (since it can't) a better solution is to have the php script right out a flat file that gets included. Then you may be able to set up a cronjob to hit the php file every so often to renew the flat file.



.:[ Never resist a perfect moment ]:.

ShrineMaster
Obsessive-Compulsive (I) Inmate

From: Somewhere in Iowa
Insane since: Feb 2002

posted posted 11-05-2002 07:19

Time for an alternative. Here's one way to add a PHP driven element to a static page, but it'll require the end user to be using Javascript to see it. Have the PHP section of the page loaded via Javascript, and have the Javascript use the Document.write() function to output the content on the page.

code:
<SCRIPT LANGUAGE="JavaScript" SRC="somescript.php"></SCRIPT>



Once you know what you're going to output, put it through this, it will format the output properly for writing with Javascript.

code:
$output = str_replace("\"","\\"."\"", $output);
$output = str_replace("'","\\'", $output);
$output = str_replace("\n","", $output);

print "function dynamicstuff() {\n";
print "var text = '";
print $output;
print "';\n";
print "document.write(text);\n";
print "}\n";



And wherever you want the dynamic stuff use this...

code:
<SCRIPT LANGUAGE="JavaScript">
<!--
dynamicstuff();
//-->
</SCRIPT>



You will also need to set the header information so the php file looks like Javascript to the browser...

code:
header("Content-type: application/x-javascript");



You can also mess with the cache headers if you want the javascript to reload everytime someone goes back to the page.

The neat thing about this is that you can use it to remote host just about everything on a site. This can also lead to draw backs of other people loading your stuff on their site, so check referers to be sure the authorized pages are loading your dynamic content.




[This message has been edited by ShrineMaster (edited 11-05-2002).]

Red Ninja
Bipolar (III) Inmate

From: Detroit, MI US
Insane since: Mar 2001

posted posted 11-05-2002 16:56

Hey, those are all great suggestions! Which one do I pick... I'm like a kid in a candy store.

Thanks for the excellent response guys.

« BackwardsOnwards »

Show Forum Drop Down Menu