The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

2 Pages V < 1 2  
Reply to this topicStart new topic
> SSI includes - Apache, date formats
jimlongo
post Oct 27 2006, 09:10 PM
Post #21


This is My Life
*******

Group: Members
Posts: 1,125
Joined: 24-August 06
From: t-dot
Member No.: 16



I think you might be caught up with the term .htaccess . . . for instance in my Cpanel the directives for PHP make no reference to .htaccess, they try to make it user friendly by eliminating the magic behind the curtain.

Like Christian said, the shortest route may be just to contact your provider. Tell them you want to enable php to be parsed within html documents. It's a pretty common request.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Brian Chandler
post Oct 27 2006, 10:39 PM
Post #22


Jocular coder
********

Group: Members
Posts: 2,298
Joined: 31-August 06
Member No.: 43



QUOTE(Christian J @ Oct 28 2006, 02:00 AM) *

QUOTE(jimlongo @ Oct 27 2006, 04:33 PM) *

To be able to run php within an html document you need to add the following directive in your .htaccess file

CODE
AddType application/x-httpd-php .php .php4 .php3 .phps



The above makes the PHP engine look for PHP scripts in files ending with the specified extensions .php .php4 .php3 .phps. To make it work with .html extensions you must add that one too. You can probably delete the rest if you're not going to use them anyway, but maybe it's good to keep at least .php (like if you include a .php file in a .html file)?


No, you don't need the extensions of files that will be included. The .htaccess thing tells the server to pass http requests for these types of file through the PHP interpreter - but once the PHP interpreter is looking at a file, it looks at everything, including 'included' files of whatever type or flavour.

User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Oct 28 2006, 07:03 AM
Post #23


.
********

Group: WDG Moderators
Posts: 7,935
Joined: 10-August 06
Member No.: 7



QUOTE(ShadowyBob @ Oct 28 2006, 02:41 AM) *

CODE
<html>
<?php phpinfo(); ?>
</html>



As a side-note I don't think you should use those HTML tags, the phpinfo() function creates all the HTML.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
ShadowyBob
post Oct 28 2006, 08:43 AM
Post #24


Advanced Member
****

Group: Members
Posts: 101
Joined: 6-October 06
From: Peterborough, UK
Member No.: 354



Thanks Christian J. As another aside does it matter if a file has the extension .htm as opposed to .html?

jimlongo, you're right, I think I'll have to short-circuit all this by using the 1 a minute phone call (but, of course, not available at weekends)!!

Brian, so are you saying all that is needed is
CODE
AddType application/x-httpd-php
?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
jimlongo
post Oct 28 2006, 09:54 AM
Post #25


This is My Life
*******

Group: Members
Posts: 1,125
Joined: 24-August 06
From: t-dot
Member No.: 16



QUOTE(ShadowyBob @ Oct 28 2006, 09:43 AM) *

Thanks Christian J. As another aside does it matter if a file has the extension .htm as opposed to .html?

jimlongo, you're right, I think I'll have to short-circuit all this by using the 1 a minute phone call (but, of course, not available at weekends)!!

Brian, so are you saying all that is needed is
CODE
AddType application/x-httpd-php
?


I'm no expert, but by my reading of the Apache docs http://httpd.apache.org/docs/1.3/mod/mod_mime.html#addtype you do need to add the extensions of filetypes you want parsed for php. If you want to have php parsed inside of html documents you need to add it to the directive. If you want to use .htm as well as .html then add that
CODE

AddType application/x-httpd-php .php .html .htm  
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Oct 28 2006, 10:28 AM
Post #26


.
********

Group: WDG Moderators
Posts: 7,935
Joined: 10-August 06
Member No.: 7



QUOTE(ShadowyBob @ Oct 28 2006, 03:43 PM) *

Thanks Christian J. As another aside does it matter if a file has the extension .htm as opposed to .html?


No, not as long as .htm is specified.

QUOTE
Brian, so are you saying all that is needed is
CODE
AddType application/x-httpd-php
?


I think Brian meant that you don't need to specify the extensions of included files (but you must still specify the including files). So this:

CODE
AddType application/x-httpd-php .html


will switch on the PHP engine for .html files. Then if e.g. foo.html contains

CODE
<?php include('foo.txt'); ?>


foo.txt will be included, even though .txt is not specified in the AddType directive. You can even put PHP inside foo.txt:

CODE
<?php echo 'This is in foo.txt'; ?>


and it should run in foo.html.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
ShadowyBob
post Oct 28 2006, 08:12 PM
Post #27


Advanced Member
****

Group: Members
Posts: 101
Joined: 6-October 06
From: Peterborough, UK
Member No.: 354



Thanks jimlongo and Christian J. I'll report back after having a word with my server help desk.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Brian Chandler
post Oct 29 2006, 12:53 AM
Post #28


Jocular coder
********

Group: Members
Posts: 2,298
Joined: 31-August 06
Member No.: 43



QUOTE(Christian J @ Oct 29 2006, 12:28 AM) *


I think Brian meant that you don't need to specify the extensions of included files (but you must still specify the including files). So this:

CODE
AddType application/x-httpd-php .html


will switch on the PHP engine for .html files. Then if e.g. foo.html contains

CODE
<?php include('foo.txt'); ?>


foo.txt will be included, even though .txt is not specified in the AddType directive. You can even put PHP inside foo.txt:

CODE
<?php echo 'This is in foo.txt'; ?>


and it should run in foo.html.


Not only "should", it will. And not only you can put '<?php' inside the included file, anyone can. So an important security notion is that you must never use "include" on anything that might have been supplied by a user.

User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
ShadowyBob
post Oct 29 2006, 11:12 AM
Post #29


Advanced Member
****

Group: Members
Posts: 101
Joined: 6-October 06
From: Peterborough, UK
Member No.: 354



QUOTE(Brian Chandler @ Oct 29 2006, 05:53 AM) *
Not only "should", it will. And not only you can put '<?php' inside the included file, anyone can. So an important security notion is that you must never use "include" on anything that might have been supplied by a user.


Excellent tip thanks Brian
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
ShadowyBob
post Nov 6 2006, 08:36 AM
Post #30


Advanced Member
****

Group: Members
Posts: 101
Joined: 6-October 06
From: Peterborough, UK
Member No.: 354



Right - after what seems an age, I'm back with some more information and would love some more help please:

1. Information from server help desk -
QUOTE
...your www folder is the top level your programs can run from and you may require to amend your scripting to reflect this...

2. If I create an .htaccess file on my root directory with the line
CODE
AddType application/x-httpd-php .html .htm
all the pages with
CODE
<!--#include virtual="/included/foo.htm" -->
show an error message instead of the included file.
3. If I add the line
CODE
Options + Includes
to the .htaccess file, I get the Internal Server Error message.

Any suggestions?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Peter1968
post Nov 6 2006, 03:49 PM
Post #31


Serious Coder
*****

Group: Members
Posts: 448
Joined: 23-September 06
Member No.: 213



It's Options +Includes (no space there), and in the AddType directive, get rid of .htm and .html, put .shtml there instead and try naming your SSI-enabled files with the .shtml extension.

Failing this, google for the XBitHack method.

This post has been edited by Peter1968: Nov 6 2006, 03:49 PM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Nov 6 2006, 03:58 PM
Post #32


.
********

Group: WDG Moderators
Posts: 7,935
Joined: 10-August 06
Member No.: 7



QUOTE(ShadowyBob @ Nov 6 2006, 02:36 PM) *

2. If I create an .htaccess file on my root directory with the line
CODE
AddType application/x-httpd-php .html .htm
all the pages with
CODE
<!--#include virtual="/included/foo.htm" -->
show an error message instead of the included file.


Doesn't
CODE
AddType application/x-httpd-php .html .htm
apply to PHP exclusively? But
CODE
<!--#include virtual="/included/foo.htm" -->
is SSI, not PHP. Making both SSI and PHP work on the same page is tricky if at all possible (can't quite remember).
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Peter1968
post Nov 6 2006, 04:10 PM
Post #33


Serious Coder
*****

Group: Members
Posts: 448
Joined: 23-September 06
Member No.: 213



CODE
AddType application/x-httpd-php .html .htm


Ack, should've seen that. My bad
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
ShadowyBob
post Nov 6 2006, 08:30 PM
Post #34


Advanced Member
****

Group: Members
Posts: 101
Joined: 6-October 06
From: Peterborough, UK
Member No.: 354



Thanks Christian J and Peter1968.

Re .htaccess, I got rid of the space between the '+' and the 'Includes' - made no difference - still the Internal Server Error. I then removed the 'AddType...' declaration and the site was again accessible. It certainly seems that the two don't go down well together!

I reckon I'm going to stick with the SSI 'includes' - at least I know it works (and it doesn't need the .htccess file)!

Do I now take it as a certain that the two can't be mixed or is there somewhere I could go to find out?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
jimlongo
post Nov 6 2006, 10:00 PM
Post #35


This is My Life
*******

Group: Members
Posts: 1,125
Joined: 24-August 06
From: t-dot
Member No.: 16



They should work together.

Since you say you can use SSI without the .htaccess why not try it with just the AddType declaration for php in the .htaccess file and see if that works. Cause the Includes line is not needed for php parsing.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Nov 7 2006, 08:48 AM
Post #36


.
********

Group: WDG Moderators
Posts: 7,935
Joined: 10-August 06
Member No.: 7



QUOTE(ShadowyBob @ Nov 7 2006, 02:30 AM) *

Do I now take it as a certain that the two can't be mixed


They might work if you use .shtml and/or .php extensions. Perhaps you can use .html for one but not the other. But I haven't been able to make both SSI and PHP work with .html extensions (yet).
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
ShadowyBob
post Nov 8 2006, 04:39 PM
Post #37


Advanced Member
****

Group: Members
Posts: 101
Joined: 6-October 06
From: Peterborough, UK
Member No.: 354



Thanks jimlongo, but see my post above:
QUOTE(ShadowyBob @ Nov 6 2006, 01:36 PM) *
...
2. If I create an .htaccess file on my root directory with the line
CODE
AddType application/x-httpd-php .html .htm
all the pages with
CODE
<!--#include virtual="/included/foo.htm" -->
show an error message instead of the included file.
...


Thanks also, Christian J if you manage it let me know! In the meantime I'll keep looking and experimenting.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

2 Pages V < 1 2
Reply to this topicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 16th November 2018 - 05:31 AM