An Introduction To Php Computer Science Essay

Published: Last Edited:

This essay has been submitted by a student. This is not an example of the work written by our professional essay writers.

PHP is an open-source server-side scripting language that purposely designed for web development and PHP freely downloadable from PHP commands can embed with HTML pages. PHP's syntax is similar with C and Perl programming languages. This makes PHP easy to learn by anyone who's with basic programming languages. PHP offers connectivity to most common databases and external libraries. By having connectivity with databases, developers can create dynamic web pages. By earlier stages, PHP is designed to develop dynamic web pages, and now its focuses mainly on server-side scripting. Server-side web scripting technologies enable the website to working with more complex function instead of simply function returning the requested HTML files. Example of complex function is performing complex calculations, working with database and much more. PHP is also scripting language which is more than a server-side technology only where programmers can use to create PHP script pages. However, PHP can used to build custom-made database-driven response website, but it will still display a static, simple web page. Therefore, it will require client-side technology such as JavaScript and AJAX.

JavaScript is a client-side scripting language which can en-rich the web pages design such as include onmouseover effect apply to menu button. JavaScript is supported by all web browsers without acquiring users to install additional plug-in to run the script. JavaScript is not suit to use to calculation because it must reach in one set at client browser for processing. Therefore, it seems to be no secure but it used better to design dynamic webpage.

To build a more powerful web page, we can combine up HTML with server scripting language and client scripting language.

Advance PHP Function

Create Thumbnail

PHP not only can combine with HTML scripting, PHP also can combine GD Graphic library. GD Graphic library is open source code library which is using for the dynamic creation of graphic by programmers. GD library usually using to create PNG, JPEG, GIF images among other format which to generate chart, graphic, and thumbnail. GD library also can move the create images into specific folder that programmer wish to located.


Create or Delete Folders / Files

PHP has a function which can allow programmers to create or delete folders / files. This function allows the system automatically to create or delete folders /files for programmers' pre-set function for certain purpose.

If the files or folders do not exist, then programmer can create folder or file with simple code function which is call touch() function. Programmers can also set the path for creating the folder or files which using the path string added in before the folder or file name. If the file or folder is not existed, the file will be created as new. If the file or folder is existed, the contents will not be edited or changed but it will update the modification date to be the time that function executed.


Programmers not even can create new folders or files, programmers can remove the existing files or folders with using unlink() function. As same as the touch() function, without a file path then it will be remove the file which consists the filename. If the unlink() function with file path, then it will follow the path to delete the file.


Create and Delete Sessions

Session functions provide a unique identifier to each user, which can used to keep track and used that information to link session with the database to retrieve values. Usually sessions are used to record user id where it is used to verify the user id, password, and access level.

Programmers can start the session with calling session_start() function in each script page. After start the session, then programmer can directly access the session variables.


Programmer can set their own session variables as their own understandable variable. Because session do not have any rules of setting session variables, the main syntax of setting session variable is no spacing between the words. In session, programmer using underscore ('_') to replace the spacing such as "sessions_id". Programmer can easily to assign the session variable with value, example:


To print out the records in session:


After programmer create sessions, if programmer did not destroy the sessions then the session will be always stored until the browser closed. But PHP scripting language also allow programmer end the session timing manually. PHP support up 2 types of ending session timing manually which are destroy all the sessions created and destroy one by one session.

Destroy all sessions created.


Destroy one by one session.


Example for using session as authentication features:

Allowing users to upload files

PHP support files upload feature, beside that, this feature also allow programmer to retrieve the information of the file uploaded such as name, path to temporary file, size, and type. The syntax code to apply the file upload feature by writing 'ENCTYPE="multipart/form-data"' into the form tag of HTML syntax.

PHP support up to maximum file size by default is 2MB but PHP also allow programmer to set their own maximum file size. After the maximum size is set, the PHP will return an error on the upload function. Programmer also can detect the type of file that users upload for validating and make sure the file uploaded is the correct type.





From the code example, the maximum file size for upload is set as 100KB which mean users can't upload the file that more than 100KB.

This screenshot below is PHP upload file with using AJAX where it used to real time upload the images without any redirect page.


Checking Email Validation

PHP also support email validation for scripting. This function will enable webpage to avoid spamming from Internet users that who intend to crash the web server.

eregi("^[_a-z0-9*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)

The above syntax is using to validate the email; programmer can use this function to validate the email that users key-in into the form for register or any purpose. If found error from the validation, programmer can set the processes after the validation.

Including codes from other files

PHP can include coding from other files. This feature can allow programmer to arrange the coding structure better where programmer can combine all the function into the single PHP scripting file.


This include() feature basically programmer used to include coding from other files. In a PHP scripting page, programmer can include more than 1 PHP scripting or text files into a single scripting page.

Include JavaScript functions


As shown in the screenshot above, PHP is able to call the JavaScript functions in to PHP scripting which used to increase the effect for interfaces. As in the screenshot above, the JavaScript function is called onmouseover().

Create Dynamic Website with MySQL Database

What is Dynamic Website? Previously HTML will only support static website which mean the website will not able to link with database and not flexibility to change the website contents by server itself. Dynamic Website can flexible to change the display contents and displaying different contents from time to time. Besides that, users can edit the displaying content without major editing on the scripting, because they only required editing the records that stored in the database. Dynamic website is also known as Database-Driven website.


Figure 3.1 A (simple) illustration of a static website as compared to a dynamic website from

Dynamic website can define by several types:

Website can respond to Internet user by different parameters.

The dynamic websites can set to be display different contents based on the time of day. Example, e-commerce website having concept to have different promotion on different days such as promotion on Monday is having 30% discount, and Tuesday is having 20% discount.

Having interfaces where administrators can maintain and change the websites' contents.

This interfaces can call as Back-end webpage where usually use for administrators to manage the contents. This interfaces usually programmed with the access level to avoiding unauthorized users to edit the contents and any records without the owner noticed.

Dynamic websites are having "memory".

This "memory" is also called as records. These records are stored into database such as MySQL, Microsoft Access and etc. These records are always able to update from time to time. Therefore, dynamic website can provide user registration and login function and etc. This could help to increase the interesting users to visit the websites.

Easy to maintain and upgrade.

Programmers can easily to edit or upgrade the existing website display because programmers modify or change the display format and then only retrieve the data from database to be display as contents. Example, product previously only displaying the details and images only. Later, programmers can add in pricing column to display without editing the previously details and images display format.

Integration PHP with MySQL

When expecting to generate dynamic website then programmers are required to implement the back-end data or information storage such as database. There are many databases management system that available but commonly programmers choose MySQL for PHP scripting websites. Without implement database, the website will be slightly defined to be useless. Because that website will be only used to display static contents which mean whenever Internet users visit and will only view the same contents. Database functionality is generic whereby programmers can use it with little effort.

Connecting to MySQL

Programmer must call this function as first function for using database storing record function. Without this function, all of the function that provided by MySQL is unable to use. The basic syntax for the connection is:

mysql_connect("hostname", "username", "password");

This function will return the connection index if the connection is successful connected then return TRUE. If the connection is failed connected then return FALSE.

Execute MySQL queries

After connecting to the MySQL, programmers are required to choose the database for the connection before using the MySQL function such as INSERT INTO, UPDATE, DELETE and etc. The syntax for execute MySQL query is:


Working with MySQL data

After selecting the database, programmers are allowed start coding with the database either retrieving data or storing data. The syntax is:

$sql = "SELECT QUERY";


Advantages of Using PHP

It is inexpensive and open source

The cost of applying PHP web development technology is inexpensive, can also declare as free because PHP is an open source web development technology. This means that every programmer can use PHP to code their web pages program freely. Although if PHP is been charged, programmers will also receive benefit more than what programmer need to paid for the charges.

It is compatible with multiple operating system

PHP can runs on multiple operating systems such as Windows, Linux, Mac OS, and UNIX. If compare to ASP, ASP only able to be used in those Microsoft Internet Information System (IIS) platform which it limit its availability to Win32 based server. This is the drawback of ASP where cause PHP becomes popular web development technology.

It is easy to use

Since C and C++ languages are the root syntax of PHP language. Therefore, PHP syntax is similar with C and C++ language syntax. So, programmers are more easily to learn and understand PHP language and syntax. PHP contains many features and functions for creating dynamic web pages and PHP designed to be easily to include into HTML files.

It is fast

PHP language designed to embed in HTML code, therefore the response time is faster than ASP. Because ASP is heavy language and this will cause the response time become slower.

Technical support is easily available

Since PHP is open source web development technology, therefore the coding is more widely learned by programmers. A large number of users can provide free support via email, or forum. But ASP doesn't having many free supports available to assist the programmers when programmers faced problems on coding.

Compatible with databases

PHP includes functionality designed to interact with specific databases such as Oracle, Sybase, generic ODBC (Open Database Connection), MySQL and etc. Programmers will have more choices to select database system for their web site.

PHP scripting is more secure

PHP scripting code is always hidden from the web browsers. The users are not able to view the PHP codes. But JavaScript or other languages can be view from browsers through browser's web development plug-in such as Mozilla Firefox's Firebug plug-in.

Example JavaScript code from Firebug(Mozilla Firefox extension):


Drawbacks of PHP

Non-Strict variables and types

PHP language does not have any strict data types which mean the variables don't need to declare before use. This way the variables management and usage will become simple and easy to take care. But it also can lead to those inexperienced programmers and will also cause bugs or errors that could hardly to traceable. PHP scripting application such as Adobe Dreamweaver doesn't support the error detection for the PHP scripting as Microsoft Visual Studio support the error detection before compiled the scripting web pages.



Event functionality lack in PHP

This is big drawbacks of PHP that always lack of events. Events enable programmers to set or attach behaviors to objects which are activated when certain conditions meet and these conditions declare as an event. Many object-oriented languages support these events with differently. Some of them use a simple approach, such as JavaScript or VB.NET but some of them use higher approach.

Registering global variables

Assigning global variables can simplify the request parameters processing easier to programmers. However, this programming technique will reflect drawback to the program. When registering global variables feature is turned on, the "register_globals" option will be injected the scripts with HTTP request variables. Since PHP doesn't require any variable initialization, hackers using this weakness to write-in the malicious code into the scripts. This feature was still included into the PHP 5 and default set to disable, but programmers are still able to use it. Global variables registration will disable after the PHP 6 version released onward.

Example of Misuse with register_globals:


Naming conversion and functions library consistency

Naming conversion in PHP are similar with Java which is the syntax is concerning about case sensitive. In PHP syntax, every variables and function names must start with lower case, class name and constant names must be in capitals. However, the variable names are case-sensitive but function names are not case-sensitive.


The "FoR" syntax and the "EcHo" syntax will not resulting any errors but the "$count" variable declared in lower case and use it with "$Count", this will resulting to the scripting debug with endless loop.

Comparing PHP with other web development technology

Compare PHP with ASP.NET

There are many web development technologies available for creating dynamic web pages. The most common and popular web development technology on the electronic market is ASP and PHP. Both of these technology is head for same goals, each of them will having their advantages and disadvantages. The comparison as below:


From the comparison of PHP and ASP.NET, PHP can define to be much better than ASP.NET. Because PHP is an open source technology which can results PHP cheaper than ASP.NET. Since ASP.NET requires win32 to run the scripting, therefore the cost will be more expensive compare to PHP.

Windows Web Hosting

24 months: $9.95 per month

PHP Web Hosting

24 months: $4.95 per month + FREE setup + FREE Domain


Adapted from


Adapted from

The speed comparison is based on 400 pages and 266,479 words. Since Internet speed provided in Malaysia is limited compared to other countries, Fastest Internet speed in Malaysia would be 4Mbps with RM268 per month; most Malaysians were signing with 512kbps. Therefore, programmers have to reduce the speed for loading the webpage where ASP having slower loading speed compared to PHP but ASP.NET will run code faster than PHP.

Mostly website's owners are for wider area for their company website especially E-commerce website. ASP.NET required win32 platform in order to run the script. Win32 platform that installed in server will consume higher cost when purchase domain name. This point is the main drawback causing PHP became the most adapted programming language.

As from the research done by "Ventura IT", stated that PHP had been installed with more than 20 millions websites and 1 millions web server.

In PHP 4.0, validation exception is not supported where programmer required to custom their own exception function. But this exception is included with the PHP 5.0.

Compare PHP with Flash


Flash website must require the plug-in from Adobe Flash Player or Microsoft Silverlight in order to load "swf" file type. Although the plug-in is installed, it must also be sure is the latest version of Flash plug-in. If the version is outdated, the "swf" might not function well as created. PHP website doesn't require any plug-in beside that PHP is supported by all browsers by default. Most Internet users are not with computer skills which they do not know well on how to install the plug-in since plug-in is not pre-installed into the web browsers.

Flash website doesn't need to reload any page of each request when there is under a single swf file and it will redirect directly without any refresh. PHP website by default is required to reload the pages because PHP is react based on the URL requested. But PHP website can be avoid the page to reload after each request through implement AJAX plug-in into PHP website. The combination is require more programming skills which not every programmers know how to implement.

Flash website often demands a large amount of file size because Flash website is saved into a flash video format called swf. When there is a large amount file size, then it will be reflecting the loading time. In PHP website, it usually is in small file size unless there is a lot of coding wrote in the files. But it compared to Flash script file, PHP script file will always be smaller than Flash script file.

Flash website is able to ease the programmer to develop same interface for different web browsers. Flash website is embedded into HTML files with video format which will not be change in different web browsers. But in PHP, programmers need to repeat check with different web browser to implement the same interfaces. Although sometime the web page interfaces will not able to 100 percents same in all web browsers. This defined as Pixel Perfect.

Flash website able to create 3D view for the interfaces or the product images. But PHP doesn't support any 3D view interfaces, this could be the strong point for Flash scripting language. 3D interface can used to show to Internet user about the product on how it shows in all sides. This feature is what users wish for when the shop online since they aren't able to touch and feel the products.

Flash website will have difficulty on the printing page since Flash is video format the web page is not able to be print through the browser print document function. Especially, users want to print the product specification but they are not able to do so. PHP can easily print page through the browser print function because PHP interface is using HTML to code the interfaces and apply CSS for the styling. Print document will not be troublesome in PHP compare to Flash website.

The Future of PHP

The fact that PHP is an open-source programming language makes PHP having the strong point to against with its competitors. As PHP is open-source, it is cheaper than other web development technology such ASP.NET charged for the win32 platform. Besides that, website owner also need to concern about the cost of developing the website. If using ASP.NET to develop website, the cost of developing the website need higher cost for purchase hosting domain to publish the website. PHP will suitable for the small organization or new organization which they want increases their business to the global business. These organizations can save up the domain cost and used it in other sections such as advertisements since PHP is cheaper than other web development technology.

Besides of PHP is cheap, PHP response is faster than other web development technology. As Malaysia's available Internet speed is quite slow and it might not able to stream a large file size's websites. Although currently Streamyx (Malaysia biggest Internet Service Provider) having 4Mbps Internet speed available for Malaysian to subscribe. Based on the Internet speed provided from Malaysia network provider, so that PHP may be using more in the future. As Flash website require higher Internet speed for stream the flash video file and Flash website is not suggested to develop for any E-commerce website. Because the E-commerce website transaction should not dropped or failed in the process of transaction.

Windows Web Hosting

24 months: $9.95 per month

PHP Web Hosting

24 months: $4.95 per month + FREE setup + FREE Domain

Figure 7.1 Web Hosting Price retrieves from

ASP.NET will also take longer time to response compared to PHP. Besides that, PHP scripts are easier to learn compared to other languages and easy to understand. PHP developer can easily to figure the solution by themselves, if they are unable to figure out the solutions. Programmers can easily to get support from PHP programmer through Internet. There are many PHP support forum is able for any PHP programmer to post their problems and get solution faster than other languages.

PHP is easiest to operate with little requirements compare to ASP.NET and Flash whereby ASP.NET require win32 platform as primary requirement. Flash is requiring the users' web browser to be installed with latest version of Adobe Flash Player and Silverlight. When version is outdated, users are requiring to update the version from time to time to avoid unnecessary errors or bugs occurred. Since PHP doesn't require any requirements to load the website, PHP will more able to use in the future.

PHP is also more secure from other programmer to get the script sources without the owner noticed compared to JavaScript. Because in web development tools supported by web browser such as Mozilla Firefox's Firebug extension or through view source feature provided by web browsers. These few ways to view source code, PHP codes are also hidden where programmer can protect their codes.

Critical Evaluations

Why use PHP to develop my Final Year Project

PHP is a programming language that programmers used to develop online website such as E-commerce website. Reason that I choose this PHP programming language to develop my Final Year Project is because PHP is open-source and it is free. PHP also able to be use mostly all web browsers because PHP is supported by all browsers whereby ASP.NET require win32 platform and Flash require Flash Player plug-in. Besides that, ASP.NET and Flash development cost is higher than PHP web development technology.

As I had wrote in previous chapter, if compare to ASP.NET and Flash, PHP will have more supports from PHP website which can help me and giving me solution in completing my Final Year Project for the errors and bugs I will faced. Besides from PHP website, there still a lot of forum that we can use to consult the bugs and get solution from PHP programmers. Usually asking question in PHP forum will receive the reply for the solution within one day from programmers.

Although PHP have lack of functionality, but PHP programming language able to embedded with other programming languages such as JavaScript and AJAX programming languages. Programmers can use this feature to increase functions and the value of the website. Besides that, PHP scripting codes is always hiding from users especially other programmers that intend to know how the website is scripted where programmers can't get the function script codes and reuse the function script codes in their website. Nowadays, PHP is widely used in web development technology and PHP also is improving object-oriented capabilities, providing try/catch handling, and etc.

PHP can use several types of database system such as Microsoft Access, MySQL. PHP have more choices for programmers when developing dynamic website. I choose to use MySQL database language and third-party software called phpmyadmin. MySQL database language is common database language which the database language will have many functions that can support to common usage for database storage. Phpmyadmin third party software will have user authentication to the database which security issue must be concerned when creating website.

Sessions features that supported by PHP web development technology is able for programmer to used for make sure the website is secure and flexible. Especially we can use it to authenticate the authorize users and their access level and avoiding them access to the unauthorized features. Sessions also can used to retrieve users information for any usage design in the website.

Lastly, as my partner and I were interviewed the real company, E-life Technology SDN BHD and they did intend to propose their company business to the Internet. Therefore, we plan to purpose an E-commerce system for their company business. After we complete this system with using PHP, then we can directly propose to the company without rewriting the website with same functions and codes into the web development language such as PHP, HTML and ASP.NET.