Forum Moderators: coopster

Message Too Old, No Replies

A beginners guide to PHP

A starting point...

         

Steerpike

5:46 am on Sep 19, 2006 (gmt 0)

10+ Year Member




A beginners guide to PHP

This is not a ‘how to’, this is a ‘what is’ or a very simple, generic document designed to give people just starting out a sense of scope and to give them a very, very simple, non-threatening starting point for more complex research into what can often be a daunting concept.

What is PHP?
PHP is one of several, usually interconnected, tools available for displaying and interacting with information on the web.
The tricky thing about PHP is simply this: php is a server side language. What does that mean? Well let’s look at the actions a website generally has to perform.

1. George opens a web browser.
2. George directs his browser to www.webmasterworld.com/index.html
3. The server at webmaster world receives his request.
4. The server at webmaster world sends the requested page to George’s browser.
5. George’s browser renders the html and javascript in the page sent by webmaster world.

Let’s take a look at the php version of the same event.
1. George opens a web browser.
2. George directs his browser to www.webmasterworld.com/index.php
3. The server at webmaster world receives his request.
4. The server at webmaster world ‘parses’ the page requested, executing all the php code within the page.
5. The server at webmaster world sends the requested page to George’s browser.
6. George’s browser renders the html and javascript in the page sent by webmaster world.

The important things to notice in the second event is:
1.The php happens at the server level, not on George’s browser like html and javascript.
2.The end page, to George’s browser, is exactly the same. That is, to George and his browser, index.html and index.php may as well be exactly the same page. Due to the the fact that php is a server side language, the end result of the code has to make sense to the browser that’s interpreting the information sent.

The other important thing to note is that ‘parses’ is a fancy word for ‘reads and executes the commands written within’.

So, we now understand php is a server side scripting language, the next question is what does a server side scripting language do and why would we ever need to use one?

What does PHP do?
By itself PHP really isn’t all that exciting, most of the things you can do with PHP as a solo tool you could do with javascript or with HTML, although it is very good at lowering the amount of work you have to do as a developer to relate the same amount of information to the user.
To use an analogy of Richard Feynman’s, let’s say you’d never experienced the rules of mathematics before and a mathematician asked you to subtract 300 from 500 and gave you 1000 beans to do it with. First you’d count out 500 beans and place them in a little pile. Then you’d remove 300 beans from that pile and count the number of beans left over to reach your end result of 200. What a long and laborious process!
Except, we know that there’s an easier way to do it: we can use mathematical rules to quickly and efficiently do 500-300=200. That’s what PHP can do for HTML. It can turn long, laborious processes into much more simple executions just by knowing the rules of the language.

PHP on it’s own can also:
Allow your users (or you) to upload files to your webserver.

Manipulate and change images.
Send email.
Respond to a form.

More importantly, PHP can talk to databases.

PHP and Databases.
Databases are stored on a server.
Your webfiles are stored on a server.
Your users want to visit your server.
PHP is a server side language.

It’s a match made in heaven! Databases (large storage repositories) sit on a server, just waiting for someone to come around asking them questions. Users want to ask questions but all they have is a browser and (as we already know) all the browser can do is display html and execute javascript, thus PHP comes to the rescue, bridging the gap between database and user. Using PHP your visitors can submit questions to the database, the database can get a result and php can translate that result into something that will make sense to the browser before sending it back to the visitor.

coopster

5:26 pm on Sep 27, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



By the way, Steerpike, this is well stated. I think sometimes we get to certain levels of knowledge we assume that everyone "knows" this already. A good reminder for each of us to consider. Thanks.