Category Archives: PHP

Php tutorials

Browse Sub-Categories:

How to Check System Load in Php on Linux

By | August 8, 2020

System load System load is a measure of how busy the system is running the processes. Higher system load simply means more processes are running and more are waiting to be run. When coding php applications, it sometimes is useful or necessary to find the current load on the server/system. For example if you want… Read More »

How to enable encoded forward slash in path-info in mvc or CodeIgniter app urls

By | May 16, 2023

Path Info Urls When using path info data , the urls of codeignitor apps or your custom mvc frameworks looks something like this example.com/index.php/controller/method/param1/param2 or example.com/controller/method/param1/param2 The path info data can be used to specify which class and method should be invoked on server application. Forward slash in parameter Sometimes it might so happen that… Read More »

How to use “path info” with PATH_INFO / ORIG_PATH_INFO in Apache Php Setup

By | May 15, 2023

The PATH-INFO is the extra path data that follows the name of a script (or servlet) in the URL. Its different from query string. Here is a classic example: https://www.examples.com/index.php/some/path?a=b Now, over here we are actually invoking the script index.php only. However also providing some path-info data “/some/path”, which is then followed by the query… Read More »

PHP redirect – go back to previous page

By | September 1, 2023

To go back to the previous page the superglobal variable $_SERVER can be used. $_SERVER[‘HTTP_REFERER’] has the link to the previous page. So to redirect simply : // Method to go to previous page function goback() { header("Location: {$_SERVER['HTTP_REFERER']}"); exit; } goback();

Backup mysql database with php and zip it

By | May 1, 2009

Many php applications prefer to backup the mysql database from within the application and save it as an archive. The mysqldump commandline utility can be used to perform this function of backing up a mysql database as sql file. The command would be like this : mysqldump –user=$username –password=$password –opt $db_name > $dir/backup.sql The above… Read More »

Php – parse text and convert urls into hyperlinks

By | May 10, 2020

The following function will parse a given text and convert all the urls into links. It does this using regular expressions. It converts email addresses to mailto links as well. Code function parse_links($str) { $str = str_replace('www.', 'http://www.', $str); $str = preg_replace('|http://([a-zA-Z0-9-./]+)|', '<a href="http://$1">$1</a>', $str); $str = preg_replace('/(([a-z0-9+_-]+)(.[a-z0-9+_-]+)*@([a-z0-9-]+.)+[a-z]{2,6})/', '<a href="mailto:$1">$1</a>', $str); return $str; }

Run php scripts from cron

By | March 22, 2009

Automatic Running In a web application there are many cases, when a certain piece of code or script needs to run automatically in the background to perform certain tasks, without the need of any user to start it. Like scraping, extracting or crawling data from web or perform some regular tasks like sending emails, system… Read More »

Get real IP address of user in php

By | December 4, 2008

Client IP address Php applications are mostly web based and often need to get the ip address of the user who is connecting to the application. Ip address is required for various logging purpose, geolocation service etc. The most common way to get the ip address of a remote user is by using the superglobal… Read More »