PHP Scripts for Beginners – How to Use PHP Scripts in Website Design

What is PHP?

Simply put, PHP is a programming language that is used to design dynamic web pages and websites. This part of the web design course will cover some of the aspects of this type designing script. PHP scripts are processed on the server side and the results displayed on your browser.

In server-side scripting, the PHP module attaches to your web server and tells it that files with the .php extension should PHP scriptsbe examined for PHP code and if any PHP code is found, it is executed and replaced with the output to be displayed on your web browser.

Example: If you have 2 files ‘learn.php’ and ‘learn.html’, the former will be executed by the server while the latter will be passed straight into your web browser without any PHP involvement.

These PHP scripts are executed when a certain action is performed. This could be when you click the submit button, click a link or type a URL of a web page and send it.

Once the page is downloaded, PHP stays idle until you make another request.

Because of the fact that PHP checks values in a HTML form only after the submit button is clicked, PHP scripts cannot be used for client-side validation to.

For example, check if the value in one field meets the required criteria before proceeding with other fields. If you want client-side validation, you can use Javascript or Ajax, languages that run inside your web browser itself. You can thus use both languages for a more dynamic website.

No Matter what Web Browser

As you may already have realized, the beauty of PHP lies in the fact that PHP scripts can be run regardless of the browser you are running.

Thus, when writing server-side PHP scripts, you do not have to worry about the browser compatibility or if Javascript has been enabled. Any code written in PHP will run the same in all browsers. In order for the scripts to be run, they will have to inside the PHP tags.

These tags, <?php and ?> tell PHP that everything between these 2 tags is PHP and should be executed by the server and the output displayed on the browser.

You can thus effectively use a PHP script to embed small dynamic elements inside a page. PHP scripts can also be used to submit and process form mail scripts when user-submitted comments are sent by email to the owner of a website.

PHP scriptsPHP’s ‘mail’ function is used to send an email message to website owner after, say, a user clicks the submit button. PHP is a flexible language and there are many other things that it can do.

You are only limited by your imagination. Like this web design tip? Want to learn more website design lessons from home? Take a look.

Filed under: Web Design