Sunday 28 October 2007

PHP: PHPInfo: Your first PHP Script

Now i'm no expert when it comes to PHP or HTML for that matter but I have learnt a thing or 2 along the way. I do have problems remembering it all, maybe that's my old age! So maybe it will help me if I add as much of it here as I can and if it helps you along the way then fantastic.

First of all what does PHP stand for?

Well originally Rasmus Lerdorf devised PHP sometime in 1994 for creating his 'Personal Home Page' so that's what it stood for. It eventually grew into what it is today and was then renamed PHP: Hypertext Preprocessor.

PHP pages are created in the same way that you would create any other webpage, using your favourite text editor. This can be something as power hungry as Dreamweaver or even Notepad. Just remember to save your work with the extension .php. You can use other extensions but it involves additional work and this is meant to be basic, easy babysteps so let's not complicate things to much yet.

Ok, our first script. I assume you have webhosting already sorted out and it is PHP enabled? Don't know, well let's use our first script to find out.

PHP files can also carry standard HTML, XHTML and the like therefore you need to let your server know that what follows is PHP coding so that it can be treated as such. PHP does this by using the to finish, like so:

HTML

<?php

YOUR PHP CODE GOES HERE.

?>

HTML again

Easy. Our first script will we write will output the phpinfo file which will tell you everything about the version of php running on your server. If it doesn't produce anything then you don't have php enabled on your server.

Ok here we go, open a new document and enter the following:

<?php
phpinfo();
exit();
?>

Save the file as index.php and upload to your server. Now using your favourite browser navigate to your domain and you should see something like the pic below:



IF you don't see anything then you probably haven't got php installed on your server. If you do see something like the above then congratulations you have just written and executed your very first php script.

No comments: