JohnS Posted June 17, 2015 Share Posted June 17, 2015 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 More sharing options...
Larry Posted June 17, 2015 Share Posted June 17, 2015 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 More sharing options...
JohnS Posted June 18, 2015 Author Share Posted June 18, 2015 Yes, it was quite clear, and I thought I understood it. So then why did your Fig.B of Pg.5 execute correctly? Link to comment Share on other sites More sharing options...
Larry Posted June 18, 2015 Share Posted June 18, 2015 Sorry for the confusion! It only executes "fine" in that the HTML is shown. But any PHP in the script would not be executed. Link to comment Share on other sites More sharing options...
Recommended Posts