Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

silly server hosters

Status
Not open for further replies.

MDLU

IS-IT--Management
Joined
Nov 5, 2003
Messages
102
Location
US
My goal: include text from one HTML/TXT file in another HTML file.

My hosting service does not allow me to use the convenient
<!--#include file="..." --> in my HTML, it only allows #exec commands.

My service does not support CGI scripts (and I'm too cheap to pay for it). It does support PHP.

Now, I know how to have a PHP file include text in itself, as a web page on it's own. Is there a way to use PHP within my HTML page to include a file into itself?
 
Well, i fixed it before anyone got to it. I'm pretty new to PHP, so y'all may know this, but if it helps anyone, here's my fix - the important part that I was missing is that it must be saved as a .PHP file, not a .HTM!...

<html>
<head>
</head>

<body>
<?php include("test.txt"); ?>
<p align="center">Main text.</p>
</body>
</html>
 
MDLU said:
the important part that I was missing is that it must be saved as a .PHP file, not a .HTM!

This is because the HTTP server you use (probably Apache) serves all requests for files. It will deliver a .html file (if it can) without processing the file.

If the file has an extension that it has been configured to recognise (in your case, .php) then it will pre-process the .php file (using the module/program that it knows will process that specific file type) before delivering it to you through the HTTP server.

Why am I bothering with this simple lesson? Because this same mechanism is used for all server-side scripting solutions. Whether you use .asp, .jsp, .cfm or .php they are all processed by some 3rd party program before being delivered (via HTTP) to you.

The trick to remember is that the HTTP server doesn't know anything about your code... it is only able to differentiate your pages based on their file extension.

It would be entirely possible to have a modified HTTP server that considered .html (or any extension really) files to be .php files.

Jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top