Jump to content
Larry Ullman's Book Forums

Chapter 1 - First.php Stupid Question


Recommended Posts

Re: program first.php

 

The program works fine when I enter the URL as: http://localhost/first.php

exactly as shown in Fig.A on Pg.4. So far, so good!

 

However, when I open the file using my local path: 

 

file:///Applications/MAMP/htdocs/Ch01/first.php

 

it does not execute the HTML, but displays the source code of first.php, but with the <?php ?> tag removed!

 

Fig.B on Pg.5, shows the HTML executing normally (because there is no actual PHP code between the PHP tags). You even say "not that this particular script is affected either way."

 

​Of course, if I change the name of the file from first.php to first.html, then it works as a normal HTML program, but Fig.B shows the name as first.php

 

Shouldn't your browser fail to run a local file with a .php extension?

 

Any idea what is going on here?

Link to comment
Share on other sites

I think I'm pretty emphatic in the book that you have to run all PHP scripts through a URL (http:// something). Your browser does not know how to execute PHP code. Just like your browser couldn't run Ruby or Python. The web *server* does know how to execute PHP, however, which is why you have to use http://, in order to go through a web server. 

Link to comment
Share on other sites

 Share

×
×
  • Create New...