php extension on html pages

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sarris
Forum Contributor
Posts: 137
Joined: Mon Dec 04, 2006 2:44 pm

php extension on html pages

Post by sarris »

Hi there, i have a simple question
If i have a html page (starts and finishes with <html> </html>) but i rename its extension to .php, will that page run on my server or on the clients browser?
Thanks in advance
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Did you install php on your webserver or on your browser?
sarris
Forum Contributor
Posts: 137
Joined: Mon Dec 04, 2006 2:44 pm

Post by sarris »

what do you mean?
install php to the browser?
my question is general. i have a site that consists of html and php pages.
One page that is actually html but has php extension, will run on the server or on the browser?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Usual request to a webserver for a .html file: The webserver is configured to serve the contents of the .html file as is and sending a http header Content-type: text/html. The client/browser gets the contents of the file and "knows" it's html.
Usual request to a webserver for a .php file: The webserver is configured to let php handle the request. php reads the contents of the file, parses it as a php-script and runs it (unless there are have been syntax errors). All output of the script is send to the webserver and from there to the client. The client get's the output of the php script and all generated http headers. php by default sets Content-type: text/html and outputs everything outside a <?php ?> block as-is.
Iif you just rename a .html file (without php code in it) to .php nothing changes for the client/browser except maybe one or two additional http headers like X-Powered-By: PHP/version.
Open your browser's source view. What you see is the html "running" on your browser. Usually you won't find any php code in there. If you do the webserver has probably been misconfigured.
Last edited by volka on Mon Mar 05, 2007 10:31 am, edited 1 time in total.
sarris
Forum Contributor
Posts: 137
Joined: Mon Dec 04, 2006 2:44 pm

Post by sarris »

ok...clear.
thanks
Post Reply