What Is PHP Used For?

Learn ways to enhance a website with PHP

Smiling young man sitting on couch and using laptop
Neustockimages/E+/Getty Images

PHP is a popular server-side scripting language for the web. Generally speaking, PHP is used to add a functionality to websites that HTML alone can't achieve. But what does this really mean? Here are some examples.

PHP Performs Calculations

PHP can perform all types of calculations, from figuring out what day it is or what day of the week March 18, 2046, falls on, to performing all  types of mathematical equations.

In PHP, math expressions are made up of operators and operands. Basic math addition, subtraction, multiplication and division are done using mathematical operators. The large number of math functions are part of the PHP core. No installation is required to use them.

PHP Collects User Information

Using PHP, you can let your user directly interact with the script. This can be something really simple, like collecting the temperature from the user that they want to convert from degrees to another format, or it can be more extensive information, like adding their information to an address book, letting them post on a forum or participate in a survey. 

PHP Interacts With MySQL Databases

PHP is particularly good at interacting with MySQL databases, which opens endless possibilities. You can write user-submitted information to a database, and you can retrieve information from the database. This allows you to create pages on the fly using the contents of the database.

You can even perform complex tasks like set up a login system, create a website search feature, or keep your store's product catalog and inventory online.

You can also use PHP and MySQL to set up an automated picture gallery to showcase products. 

PHP and GD Library Create Graphics

Use the GD Library that is bundled with PHP to create simple graphics on the fly or to edit existing graphics.

You might want to resize images, rotate them, change them to grayscale, or make thumbnails of them. Practical applications allow users to edit their avatars or generate CAPTCHA verifications. You can also create dynamic graphics that are always changing such as dynamic Twitter signatures.

PHP Works With Cookies

Cookies are used to identify a user and store the user's preferences as given on the site so the information doesn't have to be re-entered each time the user visits the site. The cookie is a small file embedded on the user's computer. Using PHP, you can create, modify and delete cookies and retrieve cookie values.

If you're new to PHP, hopeful this gives you a taste of the types of features this dynamic language can bring to your website. Want to learn PHP? Start with a beginners tutorial.