PDA

View Full Version : [TUTORIAL]PHP BASICS



Barely Human
11-06-2004, 12:49 AM
PHP can be a very usefull tool for creating interactive website. But it can also be very complex. In this, i shall define what php is, and how it can benefit your website.

What is PHP?

PHP stands for Hypertext Preprocesor, and is used to create dynamic websites. The bonus of using php is that all proceses are done server side, and then sent out as standard html to your browser, unlike other dynamic tools such as Java. This means that no matter what compuer you are using, mac, pc, windows, linux etc... The resulted page will always be the same.

What is a Dynamic Website??

There is two types of website, static, and dynamic. A static website has content written by an author, and stays that way until the file is changed by the author again. This can be fine for a lot of sites. But a dynamic site offers a lot of flexibilty, and to be honest, are a lot more profesinal. Lets give some examples -

Click Here (http://www.the-iq.net/tutorial/simple1.htm)

This is a very basic static website. No matter how many times you load the page, or when you load it, it will always be the same. For it to change, i will have to physically alter the file myself.

Click Here (http://www.the-iq.net/tutorial/simple.php)

This is a simple dynamic site using PHP. If you reload the page, you will see that the clock time has changed. The server has altered the file itself. Or has it??? The answer is actually no. When you requested that file, the server has read the code, and seen that the time needed adding to it. It then inserted it into a new script, which was sent to your browser.

The actual code for this page is -

<HTML>
<HEAD>
<TITLE>Test Page</TITLE>
</HEAD>
<BODY>
<div align="center">This is a simple webpage!</div>
<h3>The Date & Time: </h3>
<? echo (date ("l dS of F Y h:i:s A")); ?>
</BODY>
</HTML>

Php is an html embeded script, this means that it works pretty much in the same way as html, but you need to use different tags to tell the server what parts are php. Notice that in the above example the PHP is distinguished from the HTML with the symbols <? (less-than followed by a question mark) and ?> (a question mark followed by a greater-than). The symbol combination <? opens up a PHP statement, and tells the webserver that all statements that follow until the symbol combination ?> are PHP statements. You can also have the sequence "php" after your first question mark (<?php).

Even tho php is html based, you must save your files with the extension .php or .php3 otherwise the server wont process the php.

PHP and My SQL

In most cases, you will need to use something called MySQL for a dynamic site using PHP. This is for user input. The best way you can see this is in a forum. You can physically add your own text to the website. This is done using a MySQL database. The database has nothing to do with the actuall php files, it is a completely seperate system, and can even be run on a different server to the one with the php files on. The php script acts as a gateway to the database. Your scripting in the php defines how the database it to be displayed, where it is to be displayed, and how it can be edited by the user.

What can Php be used for

The main use for php is for forums, shops, guest books, and sites that need constantly updating.

Is there any alternatives to PHP

The only real alternative to PHP is ASP.net. ASP runs on a simliar basis to php, only there isnt as much suport for it, and the coding is a bit harder to learn than PHP. Asp does offer easier editing and a few cool features that PHP doesnt offer. Asp is also made by microsoft, which is always a downside.

John Ferraris
21-01-2005, 11:00 PM
Another use for php/mySQL we used for our website was to store all links/site text/downlaods/news items/tune info etc. in a mySQL database. Then, we coded the site in php to pull all the info off the database and spit out the html for your viewing pleasure. This meant that nothing was hard-coded into the site, making changes/additions/maitainence a doddle. A seperate sub-site called Admin was created with php, allowing any of the content to be changed or new content added without having to fire up an html editor or ftp client. It takes a while to set up, but makes maiantainance and scaling up the site as simple as logging onto the admin site and clicking a few buttons, witout any prior knowledge of php/mysql/html/ftp required. Well reccomended! :cool:

278d7e64a374de26f==