Welcome visitors of MIC Computer

Welcome to my blog. With this blog you can post your question about computer and programming for absolutely free (free consultation sponsored by MIC Computer).. Well what are you waiting for just feel free to post your question or share with me about your computer / programming experience

Wednesday, August 31, 2011

My First PHP

PHP (PHP: Hypertext Preprocessor) is a server side language (have the same function like ASP, ASP.NET, of JSP). For the first time PHP development began in 1994 when Rasmus Lerdorf made some set of perl script that he called as "Personal Home Page Tools" to maintain his `Personal Home Page`. In 1997 Zeev Suraski and Andi Gutmans, two Israeli developers rewrote the parser and formed the base of PHP3. The PHP3 was launch in June 1998 and Zend Engine was found in 1999.

PHP is a popular server side language on Linux but now we also use it on Unix, Windows and Macintosh. For the first time it was designed to run with Apache web server, but now we can run it using PWS (Personal Web Server), IIS (Internet Information Server) and Xitami.

Why we use PHP?
We use PHP to generate a dynamic HTML page. As you already know that HTML page is a static page that can only display a static information. For example you cannot display a page that show a timestamp but PHP can do it although you have to refresh the page anytime you want to see the new timestamp.

How PHP works?

  1. when user open a web page, the request was send to the web server.
  2. web server then search and execute the PHP script
  3. PHP script then produce the HTML code and send it back to the client browser
How to install PHP?
I will show you how to install PHP on Windows now.
  1. to install PHP on windows is very simple now. you can download and install a free web server software like XAMPP or WAMP here.
  2. install and follow the instruction.
  3. turn on your web server
  4. and you are ready now, just open your browser and type "http:\\localhost" that's all
Hello world
Lets make our first PHP script. But first I want to show you the similar HTML script that produce the same page on your browser. First write this code to an editor like notepad/wordpad. Then save it as first.html for html and first.php for PHP. Then open your browser and open it. (I will explain about how to open it in other topic. But you can open XAMPP/WAMP web site to do this)
HTML:
<html>
<head>
<title>My first PHP</title>
</head>
<body>
Hello World
</body>
</html>

PHP:
<html>
<head>
<title>My first PHP</title>
</head>
<body>
<?php
echo("Hello World");
?>
</body>
</html> 
 So why that we have to use PHP? try this script:
HTML:
<html>
<head>
<title>Today Date</title>
</head>
<body>
For example here just write some date because HTML can't do that.
2011 September 01
</body>
</html>

PHP:
<html>
<head>
<title>Today Date</title>
</head>
<body>
PHP can show the server time correctly, just refresh your page to update it.
<?php
echo(date("Y F d"));
?>
</body>
</html>
 Now I hope you will understand why we have to use PHP for dynamic HTML page :).

No comments: