By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,008 Members | 2,895 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,008 IT Pros & Developers. It's quick & easy.

Embed PHP script in HTML page...

P: n/a
Hi there,

The first page of my Internet website must be INDEX.HTM.
But, if I want to embed some PHP code in this page, I must rename it to
INDEX.PHP.
Easy, but not simple, because INDEX.PHP will not load as the default
startup-page of my website.

So, my question is:
How can I embed some PHP code within a normal HTML page (without using the
..PHP extension)?

Thank you in advance.

Regards,
Stefan.
Jul 17 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a

"Stefan van Roosmalen" <ro******@planet.nl> wrote in message
news:ci**********@reader11.wxs.nl...
Hi there,

The first page of my Internet website must be INDEX.HTM.
Not if you are using the Apache web server. In httpd.conf there is an entry
called DirectoryIndex which lists out the possible filenames which are
supposed to be the default index page withinn each directory. These file
names are scanned left to right, and the first one that's found is
processed. In the following example:

DirectoryIndex index.html index.html.var index.htm index.php

"index.html" comes before "index.htm" which comes before "index.php". You
can put whatever files names you like in there. Some people like
"default.html" instead of "index.html", so you see you are not stuck to a
single file name.

If you are not using Apache then read the documentation for a similar
DirectoryIndex drective.

--
Tony Marston

http://www.tonymarston.net
But, if I want to embed some PHP code in this page, I must rename it to
INDEX.PHP.
Easy, but not simple, because INDEX.PHP will not load as the default
startup-page of my website.

So, my question is:
How can I embed some PHP code within a normal HTML page (without using the
.PHP extension)?

Thank you in advance.

Regards,
Stefan.

Jul 17 '05 #2

P: n/a
Tony Marston wrote:
"Stefan van Roosmalen" <ro******@planet.nl> wrote in message
news:ci**********@reader11.wxs.nl...
Hi there,

The first page of my Internet website must be INDEX.HTM.


Not if you are using the Apache web server. In httpd.conf there is an entry
called DirectoryIndex which lists out the possible filenames which are
supposed to be the default index page withinn each directory. These file
names are scanned left to right, and the first one that's found is
processed. In the following example:

DirectoryIndex index.html index.html.var index.htm index.php

If you are not using Apache then read the documentation for a similar
DirectoryIndex drective.


IINM, you can also use the DirectoryIndex directive for a per-dir in
..htaccess files as well.

--
Justin Koivisto - sp**@koivi.com
http://www.koivi.com
Jul 17 '05 #3

P: n/a
Stefan van Roosmalen <ro******@planet.nl> wrote or quoted:
The first page of my Internet website must be INDEX.HTM.
But, if I want to embed some PHP code in this page, I must rename it to
INDEX.PHP.
Easy, but not simple, because INDEX.PHP will not load as the default
startup-page of my website.


Apache is not set up to handle PHP index files in its config file?

Can you fix that?
--
__________
|im |yler http://timtyler.org/ ti*@tt1lock.org Remove lock to reply.
Jul 17 '05 #4

P: n/a
In article <ci**********@reader11.wxs.nl>,
"Stefan van Roosmalen" <ro******@planet.nl> wrote:
Hi there,

The first page of my Internet website must be INDEX.HTM.
But, if I want to embed some PHP code in this page, I must rename it to
INDEX.PHP.
Easy, but not simple, because INDEX.PHP will not load as the default
startup-page of my website.

So, my question is:
How can I embed some PHP code within a normal HTML page (without using the
.PHP extension)?

Thank you in advance.

Regards,
Stefan.


This is a function of your ISP's web server (or how you've configured
your web server on the system you're testing this on). Apache only uses
the mod_php module when you name a page with the .php extension.

There's no way to have a "INDEX.HTM" run a php script on Apache, sorry.
So, you'll have to live with this restriction.

--
DeeDee, don't press that button! DeeDee! NO! Dee...

Jul 17 '05 #5

P: n/a
Stefan van Roosmalen wrote:
The first page of my Internet website must be INDEX.HTM.
Why?
But, if I want to embed some PHP code in this page, I must rename it to
INDEX.PHP.
Decent servers can have files with '.htm' filename
extensions parsed by PHP; any file can be, with any or no
filename extension.
Easy, but not simple, because INDEX.PHP will not load as the default
startup-page of my website.
The default file can be changed on decent servers.
So, my question is:
How can I embed some PHP code within a normal HTML page (without using the
.PHP extension)?


Configure the server to have files with a '.htm' (or
'.html', or whatever) filename extension parsed by PHP.

I'd do it differently. I'd maintain common, logical
filename extensions: files to be parsed by PHP have the
extension '.php'; HTML files have '.html'; plain text,
'.txt'; and so on. I'd also support URI persistency by
publishing URIs without suffixes, e.g.,
http://domain.example/foo , instead of
http://domain.example/foo.php .

--
Jock
Jul 17 '05 #6

P: n/a
"Michael wrote:
There's no way to have a "INDEX.HTM" run a php script on Apache, sorry.
So, you'll have to live with this restriction.


BS:

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

Daniel Tryba

Jul 17 '05 #7

P: n/a
Stefan van Roosmalen wrote:
Hi there,


Why do you keep on multi-posting? Cross-post next time!

http://www.usenet.com/articles/cross_posting.htm
JW

Jul 17 '05 #8

P: n/a
Stefan van Roosmalen wrote:

The first page of my Internet website must be INDEX.HTM.
But, if I want to embed some PHP code in this page, I must rename it to
INDEX.PHP.
Easy, but not simple, because INDEX.PHP will not load as the default
startup-page of my website.


Are you assuming the first page has to be index.htm? Because if you tried an
index.php, but didn't rename the index.htm, in most setups, the HTM would take
precedence over the PHP. If this is the case, make an index.php and rename
index.htm to something else like index-backup.htm. Also, make sure there are no
index.html, index.cgi, etc.

If that still doesn't work you can make an .htaccess file if you're using
Apache. You can go 2 routes:
Override your server's default directory index:

DirectoryIndex index.php
Or, force Apache to treat index.htm as a PHP file:

<Files index.htm>
ForceType application/x-httpd-php
</Files>

Just add whatever lines you want to the existing .htaccess, or, if one doesn't
already exist, create a file called .htaccess with whatever lines you want and
put it in your server's web root. Be careful you don't overwrite existing
..htaccess files and be aware that whatever you specify will be inherited by
child directories (i.e. if you make index.php the default directory index at
http://www.yourdomain.com/, it'll be the default at
http://www.yourdomain.com/subdirectory/).

If these options don't work, please tell us what server you're using...

Shawn
--
Shawn Wilson
sh***@glassgiant.com
http://www.glassgiant.com
Jul 17 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.