Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why PHP script is not workig in a web browser?

Tags:

php

We have all seen many question on StackOverflow that are founded upon the idea that PHP works like Javascript. Where the person clearly does not understand that PHP is a Preproccessor and only works before the page is sent out.

A clear example of this is in the following code, where runCommand() will not run when the user presses the button.

<a href="<?php runCommand(); ?>">Click Me!</a>

as it would in Javascript

<a href="javascript:runCommand();">Click Me!</a>

I've seen many questions like this that are from new people that just simply don't realize 'how' PHP works.

My question is: Where is a great resource that explains how PHP works?.

I want to be able to redirect people to a page that can get them going on the correct track and know what being a Preproccessor means.

(This also allows me to be lazy and not have to write an explanation every time it comes up, but don't tell anyone!)

If you don't know of a place that describes this well, feel free to provide your own interpretation.

As Carl Smotricz points out, there is a part of PHP that can be used outside of the browser. But I'm mainly talking about in a Apache enviorment where a user requests a web page, and expects to get something back, usually in HTML.

like image 250
Tyler Carter Avatar asked Jan 09 '10 18:01

Tyler Carter


People also ask

Why my PHP file is not working on browser?

So possible reasons could be: PHP is not installed properly on your system or the server is not properly installed. PHP module isn't loaded in your apache. You did not put your scripts in the right place.

Why PHP is not working in HTML?

The answer is in fact so simple you would want to bang your head: Simply change the file extension from ". html" to ". php"!!! Remember that you can build a webpage entirely out of PHP and all JavaScript and stuff built off JavaScript like, JQuery, bootstrap, etc will work.

How do I run a PHP file in browser?

Open up any Web browser on your desktop and enter "localhost" into the address box. The browser will open a list of files stored under the "HTDocs" folder on your computer. Click on the link to a PHP file and open it to run a script.


1 Answers

Wikipedia is always a great resource of information. I suggest:

Server-side scripting

vs

Client-side scripting


And Wikipedia also has pictures:

enter image description here

like image 198
Felix Kling Avatar answered Oct 20 '22 06:10

Felix Kling