PHP

How to create random alphanumeric password in PHP

How to create random alphanumeric password in PHP

At times, you may need to generate and provide your website user with a new or default password. For example, if a user has forgotten his/her password then you may need to generate a new password for him/her.

Or you may want to provide default password to newly registered users after they have verified their e-mail address. It is obvious that password generated in these circumstances should be random in nature.

Read More

How to track outbound links with PHP

How to track outbound links with PHP

It is important for a website administrator to track the outbound links from his/her webpages. This tells you which links are most popular amongst the users. Here, I will show you how to accomplish this task. To track and count the outbound URL clicks, we will use the following workflow:

Read More

  • Direct users to common PHP file, say count.php, with each link having a unique value for query parameter - link_id.
  • Next, store the click details in MySQL database.
  • Finally, redirect the user to the actual URL.

How to check your server status using PHP

How to check your server status using PHP

For a website administrator it is very important to determine the status of his web server on a regular basis. Here, I will show you how to check the status of a given web server by using PHP. In order to check the server status we will ping it. Also, we will calculate the time taken by the server to respond. This will give us an idea as to how fast is our server. So let's get started.

Read More

How to create QR code by using Google Chart API in PHP

How to create QR code by using Google Chart API in PHP

The full form of QR code is Quick Response code. It is a two dimensional code designed specifically to be read by smartphones. It is a type of matrix barcode. The code represents a picture where black squares of various sizes are arranged in a square pattern on a white background. This code can be used to encode any information such as text, a URL, or other data. Here, I will show you how to create your own QR code for any data by using Google Chart API.

Read More

How to extract text from DOCX or ODT files using PHP

How to extract text from DOCX or ODT files using PHP

Are you searching for a method to extract text from DOCX or ODT files using PHP? Well in this article I will show you how to do so. This technique can be used to create a web crawler and index document files based upon their content i.e. this can be used to create a document repository. The technique here doesn't involve any third party plugins or softwares. It will work in PHP 5.2+ and the only requirement is php_zip.dll for Windows or --enable-zip parameter for Linux. Actually the DOCX and ODT files are archive files whose extension has been changed from .zip to .docx or .odt. Hence we need a ZIP library for PHP in order to extract the data from them.

Read More

Display page load time in PHP

Display page load time in PHP

You must have noticed a lot of site display this message "Page generated in XX.XX seconds" at the bottom of the page. It is very easy to make and I will show in this post how to do so. It is a tool which gives you information on how optimized and fast is your site. Also you can easily identify performance issues by using this as it tells you how efficient your code is. Moreover website visitor's love this kind of statistics. So how do we get this time related information? The most efficient way to do this is that you store the system time at the beginning and end of your PHP code in two separate variables and then subtract them to get the total time taken to execute your code.

Read More

Simple Captcha using PHP with GD library

Simple Captcha using PHP with GD library

Captcha can come in handy when fighting against spam and bot attacks. It generates random images and asks the user to re-enter the characters it sees in order to verify whether user is a human or not. We will develop a simple captcha script in PHP by using GD library. The only requirement is that you should have the GD library installed. It gives you the ability to create and manipulate image files in different formats in PHP.

Read More

How to extract images from DOCX files using PHP

How to extract images from DOCX files using PHP

In this post I will show you how to extract and display images from Microsoft Word Document files (docx extension) using PHP. This can be used for creating a document repository and indexing images for it. We won't use any third party software or module for this. This code will work in PHP 5.2+ and the only requirement is php_zip.dll for Windows or --enable-zip parameter for Linux. Basically we need a ZIP library for PHP. The reason behind this requirement is that Word document files are actually archived files with there extension changed from .zip to .docx.

Read More

Detect screen resolution using PHP

Detect screen resolution using PHP

The ability to detect your website visitor's screen resolution gives you more freedom on how you want to display your website's content to the end user. This will help you to remove unnecessary scrollbars, that appear when the user's screen resolution is low, by serving the right version of the webpage. By default there is no such function in PHP which detects display resolution. Still there is an easy work around and it is achieved by using JavaScript along with PHP. Javascript provides the user's screen resolution information and this can be accessed by using the screen.width and screen.height properties.

Read More

The easiest way to highlight PHP syntax

The easiest way to highlight PHP syntax

What do you think is the easiest way to highlight PHP syntax? Well it can be done by mere one line code. Most of the people are not aware of this technique. You don't need to install any third party module or script for this. Did you know that PHP by default provides an in-built function for syntax highlighting!?  Well apparently its true! 

Read More

How to include PHP code in an HTML file

How to include PHP code in an HTML file

Yes it is possible to run PHP code inside a regular HTML file!  Apache has a predefined configuration which decides what all file extensions are allowed to use PHP code such as .php, .php3 files. While serving a webpage to the client, it (apache web server) will first verify this condition and then only it will interpret and execute PHP code snippets written inside a particular file. But if we change this default configuration of Apache web server then we can include PHP code snippets in HTML files and server will execute them.

Read More

Generate PDF using PHP

php script

In this post we will show you how to generate a PDF using PHP. We will be using FPDF, a PHP class, to generate the PDF. Generating PDFs using PHP is very easy. Let's start right away.

First of all you need to download the FPDF class. Its absolutely free . Go to their download page and download the latest version. Right now the latest version is 1.6 you can download it directly from here. Once you have downloaded the zip/tar file uncompress it. You will find a fpdf.php file and font folder inside it along with other files. Copy this fpdf.php file and font folder to your root directory where you will be writing the code. Now we are ready for the real thing! Check out the example given below -

Read More

PHP Redirect

php script

This article will show you how you can redirect users to a new webpage instead of the original one using PHP. This technique is especially useful when you are website is down or you have moved your content to a new location and you want to redirect your users accordingly.

To redirect with PHP check out the code given below. Place this code on the webpage on which you want to perform redirection.

Read More

How to Get the Current Page URL

php script

In this post I will show you how to get the current page url as shown in address bar using PHP. Extracting the current page's url is very easy in PHP as it provides an array $_SERVER which contains information such as headers, paths, and script locations.

Read More