Forum Moderators: coopster

Message Too Old, No Replies

Parse HTML or not

What am I doing wrong?

         

Essential IT

1:11 am on Aug 20, 2004 (gmt 0)

10+ Year Member



Hi Guys (oilman & henry0)
(Help keep my sanity [webmasterworld.com] 16-08-04)
Well I have tried what you had suggested, but to no avail, this may go on a bit but I don’t want to miss anything out.

Made a text file called .htaccess.txt put in the following
RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html

Uploaded it my root directory, same as files to be parsed, I have 8 files here as follows
1)test.php (<? phpinfo();?> ) this is to test PHP is working. Okay PHP 4.3
2)faster.php (test to makes sure php is working) Okay
I have tried the following set ups / combinations:
3)faster.htm normal auction template, where content should go I have inserted <?php include 'fasterinsert.php';?>
4)faster.htm normal auction template, where content should go I have inserted <?php include 'fasterinsert.html';?>
5)faster1.htm normal auction template, where content should go I have inserted <?php include 'fasterinsert.inc';?>
6)faster1.htm normal auction template, where content should go I have inserted <?php include 'fasterinsert.htm';?>
7)fasterinsert.html insert to replace content in auction template
8)fasterinsert.php insert to replace content in auction template

As you can see there are no restrictions on me using .htaccess.

You can add an .htaccess file if you want, but the former set of directives are redundant (.shtml files are already parsed as SSI), and the latter set just won't work. (not sure what this means)

Changed .htaccess.txt to .htaccess tried chmod to RW/R/R also left it blank, but still I can not get the file fasterinsert.php or .html to appear in any of the files listed above.

PLEASE, PLEASE what am I doing wrong? It has taken me three days to try and crack this but it will be worth it.

Hope you can help

[edited by: coopster at 4:13 pm (utc) on Aug. 21, 2004]
[edit reason] linked up url reference [/edit]

ergophobe

2:29 pm on Aug 20, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month




As you can see there are no restrictions on me using .htaccess.

Actually, I can't see that, which is perhaps good news, perhaps bad

If the server is set to parse *.php as php, and you are trying to make it parse *.html as php, it would appear that the .htaccess is not working. If you take away the .htaccess file, do your *.php files (i.e. the first two cases) still work? If so, then the .htaccess isn't doing anything.

Tom

Essential IT

3:23 pm on Aug 20, 2004 (gmt 0)

10+ Year Member



Hi ergophobe

Thanks for your reply I have removed the .htaccess file and the page (template) will now load where all that was happening was that the page would come up blank and the page would try open my download program but even though the page now loads into the browser where the content should be it's just blank, don’t know if this info will help but below is from my host tech dept

You can add an .htaccess file if you want, but the former set of directives are redundant (.shtml files are already parsed as SSI), and the latter set just won't work. (Not sure what this means)
Robert

ergophobe

5:59 pm on Aug 20, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Going back to your original list, without .htaccess in place do numbers 1 and 2 work?

If not, do they work when you put the .htaccess file back on the server.

brotherhood of LAN

6:01 pm on Aug 20, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



>>You can add an .htaccess file if you want, but the former set of directives are redundant (.shtml files are already parsed as SSI), and the latter set just won't work. (Not sure what this means)

There may be a directive to parse your html files as SSI's (id guess in http.conf if its not in your .htaccess). remove that and apache should recognise that html should be parsed through php

Essential IT

9:37 pm on Aug 20, 2004 (gmt 0)

10+ Year Member



In reply to both (brotherhood of LAN & ergophobe)

brotherhood of LAN
Sorry which is it I remove, I have already moved the .htaccess and the normal php pages load no problem, so what do I remove now is it the hhtp.conf? If so where do I find it and can I move it with out a problem?

ergophobe
Both 1 & 2 work and with and without .htaccess. I have tried both versions of .htaccess, as shown by oilman & henry0.

Help guys and gal’s , three days lost and none the wiser

Robert __In the words of the late Great Freddie Mercury (I'M GOING SLIGHTY MAD)

brotherhood of LAN

10:00 pm on Aug 20, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



>If so where do I find it and can I move it with out a problem?

There's something in the http.conf that lets .html extensions include SSI. I had the same problem you mention, after removing this part of in the http.conf my problem was solved (maybe ergophobe knows the part of the file I mean).

I assume there's some kind of conflict in letting .html be parsed for SSI's by Apache and also by PHP. After I changed my http.conf to disable SSI capability in .html , PHP parsed the .html as normal.

coopster

10:48 pm on Aug 20, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I think BOL may be referring to the SSI directives...
Options +Includes 
# You're probably already doing the next line...
#AddType text/html .htm
AddOutputFilter INCLUDES .htm

Essential IT

3:54 pm on Aug 21, 2004 (gmt 0)

10+ Year Member



HI Coopster

Correct me if I’m wrong but to use ssi scripts I would need to rename my pages shtml, but if I was to be able to rename them I would renamed them .php right at the beginning.

Here is a brief recap on what I am trying to achieve, I use templates in auction sites, with content these are to big to list (restrictions) have tried using iframes but does not allow the template to restructure it’s self (self adjusting table frame) so after reading up I believed that I could use the php include link, but if you read back through I believe I have tried everything there is to try. Unless someone knows otherwise?

This is no longer a project this has now become an obsession!

Is there anyone out there who can help?

Robert

coopster

5:29 pm on Aug 21, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I was just showing you were the SSI directives can be found in the Apache
httpd.conf
file. You said you "have contacted tech support", so I am assuming you are on a shared host. Knowing that, you probably aren't going to have access to the Apache
httpd.conf
configuration file as most hosts don't allow this. Also, it sounds to me like they have configured Apache Server-Side Includes (SSI) for you and have instructed you to save any files that you want parsed in this manner with a
.shtml
extension. So, in part, your following statement...

>>Correct me if I’m wrong but to use ssi scripts I would need to rename my pages shtml...

is true because your host has it setup this way for you. However, you asked to be corrected if you were wrong, so you're going to be corrected... ;)

First off, it's highly unlikely you are even going to need to be concerned about Apache SSI in this case, so if you don't want to use it or don't care to learn about it, skip down to the horizontal rule below and forget this section. Otherwise, let's clear the confusion on SSI. The default SSI configuration for Apache is as follows:


# 
# Filters allow you to process content before it is sent to the client.
#
# To parse .shtml files for server-side includes (SSI):
# (You will also need to add "Includes" to the "Options" directive.)
#
#AddType text/html .shtml
#AddOutputFilter INCLUDES .shtml

Then, to use SSI, we simply uncomment the configuration directives and name any file with a server-side include in it with a

.shtml
extension. Great, good to go. But, let's say I decide that a certain special folder on my site I want to have files with a
.coopster
extension that have server-side includes to be parsed by Apache and then assign the resulting document the mime type of
text/html
. I can create a per-directory override file (
.htaccess
) as follows...


Options +Includes  
AddType text/html .coopster
AddOutputFilter INCLUDES .coopster

...then, I drop that

.htaccess
file into my special directory. Next, I create an HTML file that has an Apache SSI statement in it and save this file with a
.coopster
extension in the special directory. That's it, I'm good to go. If I request that file in my web browser, I'll get the document with the SSI code parsed and dished up as
text/html
. So you see, you can actually tell your server to parse server-side includes any way you want, simply by modifying the extension in that Apache configuration directive.

Apache has a Tutorial: Introduction to Server Side Includes [httpd.apache.org] if you want to learn more. However, since you are using PHP, do you really need to use SSI? No. PHP is a server-side language, doing at least what Apache's SSI can do and then some. And this is an understatement! So, let's just forget about Apache SSI for now and focus on the PHP part.



Let's have a look at the latter half of your statement, which makes more sense once I had a peek at your original post on this subject (linked up now in msg#1).

>>...but if I was to be able to rename them I would renamed them .php right at the beginning.

What you really want to do here is parse other files as PHP, including

.htm
and
.html
. If your host is running PHP as module, then all you need to do is create a per-directory override file (
.htaccess
) with a single line in it.
AddType application/x-httpd-php .php .htm .html
If this does not work, then your host is not allowing overrides.

If your host is running PHP as a CGI binary, then we'll have to look at things a bit differently.

Essential IT

5:56 pm on Aug 21, 2004 (gmt 0)

10+ Year Member



Hi Coopster

I have listed below all correspondence from the tech dept at my hosting company maybe this will help.

And as I have said before I really appreciate your help.

Robert
***************************************************

<snipped email reference as per TOS [webmasterworld.com] #9>

[edited by: coopster at 6:20 pm (utc) on Aug. 21, 2004]
[edit reason] Using email snippets [webmasterworld.com] [/edit]

coopster

6:04 pm on Aug 21, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Yes, you can run a file that ends in .html through the PHP parser. We do this all the time as long as the host allows it. There is minimal overhead.

Try the single line file that I referred to in the latter half of my last post. When you save it, save it as

.htaccess
WITHOUT any extension, including
.txt
!

Essential IT

2:12 pm on Aug 22, 2004 (gmt 0)

10+ Year Member



Hi Coopster

Here is the predicament I have?

I sell items through various auction sites, I use a template for all sites (uniformity / corporate image) the template alone is 19kb; most sites have now put restrictions of 30kb. After putting in contents / description on most occasion I am now exceeding the 30kb limit, for example 45kb.
I am currently using iframes, these work but have restrictions I have to set the size for the table where it is to load, e.g. height=2900.

Now I have tried using php, using the <?php include 'fasterinsert.php'; ?> I have also tried using .htm / .html /. Inc but nothing works?

As I cannot rename the auction template .php as the only thing that is inserted in to an auction is HTML text, I need to try and set a link between the auction template page on the auction site and the php insert on my site.

I have checked with the tech dept of my hosting company, which and I have a resellers account so very few restrictions.

My intentions are to build a database of auction stock and have just one template page changing just a few lines, when stock changes.

Here is the reply from my tech dept.
You can add an .htaccess file if you want, but the former set of directives are redundant (.shtml files are already parsed as SSI), and the latter set just won't work.

You can include a PHP script from within an HTML page by using SSI, or by renaming the HTML file to .php and using the kind of code you quote above. The one thing that's not feasible to is run a file that ends in .html through the PHP.
So if any one can help I would forever grateful.

Robert

coopster

2:08 pm on Aug 23, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Did you try the recommendation in the previous post?

Essential IT

2:52 pm on Aug 23, 2004 (gmt 0)

10+ Year Member



Hi Coopster

Which recommendation in particular.

Robert

coopster

3:06 pm on Aug 23, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Create a per-directory override file (
.htaccess
) with a single line in it.
AddType application/x-httpd-php .php .htm .html
When you save it, save it as .htaccess WITHOUT any extension, including .txt and you should be able to parse any PHP within any
.htm
or
.html
file.

Essential IT

4:26 pm on Aug 23, 2004 (gmt 0)

10+ Year Member



Coopster

Here are the tasks I have just carried out but with no joy

Copied the script into a word pad saved as .htaccess and then used terrapin ftp program to move on to the home server saved in the root directory (public_html) saved as .htaccess,(removed .txt prefix) refreshed saved again for good luck.
Loaded htm page which has the following <?php include 'fasterinsert.php'; ?> inserted in to the body.

When I try to open the htm page, I get the (Action cancelled) page and download program opens up?
Robert

coopster

4:55 pm on Aug 23, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Let's try a simple example first, just to see if we can parse a file with a
.htm
extension with PHP. Create another file with only the following code in it.
<?php 
phpinfo();
?>
Now...
  1. Save it as
    myphpinfo.htm
  2. FTP it over to your server
  3. Open the page in your browser,
    http://www.example.com/myphpinfo.htm
What do you get?

Essential IT

5:53 pm on Aug 23, 2004 (gmt 0)

10+ Year Member



Nothing

Just a blank page

coopster

6:15 pm on Aug 23, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



OK, now let's just rename it and make sure the parser is working...
  1. Rename
    myphpinfo.htm
    to
    myphpinfo.php
  2. Open the page in your browser,
    http://www.example.com/myphpinfo.php
What do you get?

Hopefully, it's a page loaded with the PHP installation information and more. If so, then we are parsing PHP correctly at the server.

Essential IT

6:31 pm on Aug 23, 2004 (gmt 0)

10+ Year Member



PHP Version 4.3.8
Page loaded no prblem

coopster

6:38 pm on Aug 23, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



OK. PHP is being parsed correctly. Let's rename that file back to
myphpinfo.htm
again.

You have another file in the same directory as that file named

.htaccess
(with no extension, just dot-h-t-a-c-c-e-s-s). If you open that up and look at it, it should have only one line in it, correct? The
AddType
directive shown earlier. Can you confirm?

Essential IT

6:51 pm on Aug 23, 2004 (gmt 0)

10+ Year Member



Yes that is correct

coopster

7:19 pm on Aug 23, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



It seems as though your hosting provider has stated that you are indeed allowed to use per-directory override (
.htaccess
) files. Hopefully they have the AllowOverride [httpd.apache.org] directive set accordingly...

If this single line

AddType application/x-httpd-php .php .htm .html
doesn't parse the
myphpinfo.htm
file as PHP then we've gone beyond a point that I can help without access to the server.

Essential IT

8:06 pm on Aug 23, 2004 (gmt 0)

10+ Year Member



Hi Coopster

What can I say, except thanks for all your effort in try to resolve this problem?

Is there anything in particular I could ask my host which would help further?

Robert

Essential IT

8:12 pm on Aug 23, 2004 (gmt 0)

10+ Year Member



Hi Coopster

Came across this, not sure if it has any relevance?
Is PHP a CGI or Apache module?
PHP runs as a cgi at <snip>Example<snip> Internet – this is because it is more secure than running it as an Apache module (if it runs as an Apache module PHP runs as the same user with the same rights as Apache).

[edited by: coopster at 10:39 pm (utc) on Aug. 23, 2004]
[edit reason] removed specifics [/edit]

coopster

12:54 am on Aug 24, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Well, that statement is argumentative, at best. PHP runs as the Apache user in module mode, but if you have your server setup correctly, it's no worries.

You still have options here, but you are going to have to find out the handler name (if the hosting provider didn't use

php-script
by default) and use an
AddHandler
directive instead.
Action [httpd.apache.org] php-script /cgi-bin/php 
AddHandler [httpd.apache.org] php-script .php
Resource:
[us2.php.net...]

Note:
You would use this rather than the

AddType
directive in your
.htaccess
file.

Essential IT

5:12 pm on Aug 24, 2004 (gmt 0)

10+ Year Member



Hi Coopster

Can I say firstly a big thank you for all the time you spent trying to get my problem sorted out, but after all that it does not work?

Let me explain I have to parse using SSI so after a lot of tweaking, it worked, well sort of? It worked when I have all files and folders on the same server, and use this directive to call the page <!--#include virtual="inserts/binoinsert.htm" --> but refused to work when I tried to move the folder to another server, and had this as the directive <!--#include virtual="http://www.abc.com/inserts/binoinsert.htm" -->
I just get this error [an error occurred while processing this directive]?

So if anyone can come up with a suggestion to this nagging problem, I am open to any suggestions.

Robert

coopster

5:20 pm on Aug 24, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You can't do that. The virtual attribute of the include [localhost] element value must be a (%-encoded) URL-path. The URL cannot contain a scheme or hostname, only a path and an optional query string.

If you need to get the info from a different server, you'll have to perform your fetch operations in a cgi script local to the server. Either that or switch this Apache SSI to a PHP include() [php.net] function.

Essential IT

6:20 pm on Aug 24, 2004 (gmt 0)

10+ Year Member



Coopster

We have been down the php road, that’s what brought us onto the ssi track.

I was sent to the include link by my web host, But I am either more stupid than I look or the obvious is looking me in the face but I can’t see it?

Could I ask for a little more help, I know that you don’t learn if others do, but a little hint like how do I set up the include link, without using http etc? And what do I have to do with a local cgi script?

Robert

This 33 message thread spans 2 pages: 33