Web Hosting Talk







View Full Version : Quick PHP Question


sophic
10-08-2004, 04:25 PM
Ok, this is probably a ridiculously-easy question, but I thought I'd ask you guys/gals, the experts.

If a page has php code in it, does it require a .php extention? Or will .htm do?

Ok, laugh it up, I know that's an easy question, just curious :)

thanks!
Steven

amc-james
10-08-2004, 04:31 PM
you'll have to tell your webserver to associate .htm to the php parsing engine, but yeah. its possible.

AddType application/x-httpd-php .htm

RobeyHolderith
10-08-2004, 04:39 PM
In most server setups, yes, you need to have .php as the file extension if you want it to be ran as php. There are many ways around this, one of them is given above. If you can create .htaccess files that override global settings you can just put that line into a .htaccess file in the directory with the html files that are actually php files.

Another trick is that most server setups don't actually care about the file extension when looking for a file. If you don't want .php so show up then don't type it. Save the file as something.php and refer to it through your browser and links as simply somthing. The server will still correctly find and render the file.

samsonh
10-08-2004, 08:13 PM
or .shtml

you can set apache to parse any extension to be php and other languages. In theory, you can also put php in an asp file and outpute asp from php!

herrien11
10-09-2004, 11:07 AM
Another trick is that most server setups don't actually care about the file extension when looking for a file. If you don't want .php so show up then don't type it. Save the file as something.php and refer to it through your browser and links as simply somthing. The server will still correctly find and render the file.


What kind of server actually does that?
or is it some kind of settings with apache?

Burhan
10-09-2004, 11:18 AM
Originally posted by RobeyHolderith
Another trick is that most server setups don't actually care about the file extension when looking for a file. If you don't want .php so show up then don't type it. Save the file as something.php and refer to it through your browser and links as simply somthing. The server will still correctly find and render the file.

This is not true. The server has to be setup specifically for this. For example, the default Apache behavior is to send all unknown files as plain text.

Also, www.foo.com/file <-- that is a directory to a server, not a file (unless you configure it specifically).

herrien11
10-09-2004, 11:22 AM
then how do i go about configuring it?

RobeyHolderith
10-09-2004, 11:41 AM
People have a hard time believing this. They did last time I brought it up too. A default Apache install will act in this way. All that it needs is mod_negotiation. In fact W3c has been recommending this behavior for a while.

RobeyHolderith
10-09-2004, 11:47 AM
As an addition to the above note. MultiViews does have to be on in the directory. The default apache install does have this on by default. If your host does not, but allows you to modify options in .htaccess files then just create a .htaccess with the line:

Options +MultiViews

sophic
10-09-2004, 03:22 PM
thanks for all the help everyone! all of the posts to my question have seriously helped me out. If I can do anything to return the favor please let me know!

- Steven

ANMMark
10-09-2004, 06:09 PM
People have a hard time believing this. They did last time I brought it up too. A default Apache install will act in this way. All that it needs is mod_negotiation. In fact W3c has been recommending this behavior for a while.


This needs to be set, not a default.

Actually by default if you just type....www.domain.com/somthing

it looks for a folder called "something" if it does not find the folder it produces a 404.

I actually just ran this on a spare box to see if it was accurate, and it was not. You have to change the setting to get it to work as you explained it.