Forum Moderators: coopster

Message Too Old, No Replies

SSI on php pages?

SSI on php pages?

         

tplowe56

4:06 pm on Sep 4, 2009 (gmt 0)

10+ Year Member



Is it possible to use an include on a PHP page?

I have tried editing the .htaccess with no success. My pages are .php so I can protect 1,000's of pages with a php script.

Would it be easier to to rename the files with an .html extension, tell the server to parse html for php, and then tell the server to process the includes in the html pages?

benevolent001

4:15 pm on Sep 4, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sorry i am not able to get exactly what you mean

Is it possible to use an include on a PHP page?

Yes its is possible to include files

check out include_once , include , require , require_once functions on php.net

My pages are .php so I can protect 1,000's of pages with a php script.

I am not sure what exactly script is for?

Would it be easier to to rename the files with an .html extension, tell the server to parse html for php

You can do it easily to show .php files as .html just use mod_rewrite in apache

I hope this will give you some insight and will keep you busy.

And PS You are welcome to WebmasterWorld

tplowe56

4:23 pm on Sep 4, 2009 (gmt 0)

10+ Year Member



I am trying to use an include like this:
<!-- #include virtual= "/dhtml.inc" -->

On a page that is mostly html, but uses the .php extension so as to run a PHP script "Sitelok", which is used to facilitate password protection pages.

I'm on a shared Apache server.

rocknbil

6:12 pm on Sep 4, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Interesting question, but possibly a dangerous one, too, I think.

To include files using SSI, you have to have the server parse files with a certain extension to look for your includes. Normally this is the .shtml extension.

test.shtml

You can add other file extensions to your config, for example, have all .html files parsed for SSI directives; in this case, you'd add .php.

This is where the possible danger comes in, you're asking the server to parse all php files for SSI **and** asking the server to execute the file as a php script. It may not create a problem, but it may create some server-killing recursive loop. At the very least, the possibility exists that in parsing for SSI directives, the code in your PHP may convince the SSI parser there is an error in the file.

You're probably better off using php includes and modifying the included file so it behaves the way you want.

tplowe56

6:44 pm on Sep 4, 2009 (gmt 0)

10+ Year Member



I'm testing both htm & php pages. When I alter .htaccess to parse html for php it invokes downloading in Firefox.

using:

AddType application/x-httpd-php .html .php .phtml

This does not invoke download, but does not parse either:

AddHandler application/x-httpd.php .php .htm

tplowe56

7:07 pm on Sep 4, 2009 (gmt 0)

10+ Year Member



OK

This parses php in my html page:

AddType application/x-httpd-php5 .htm .html
AddHandler x-httpd-php5 .htm .html

When I add this below to parse for includes, include works but no parsing of the php.

Options +Includes
AddType text/html .shtml .txt .html .htm .php
AddHandler server-parsed .shtml .txt .html .htm .php

tplowe56

7:36 pm on Sep 4, 2009 (gmt 0)

10+ Year Member



Got everything working on php pages.

Used this to do the include:

<?php include "/yourfilename.php"?>

Another nubee sees the light.