Category : "PHP"

Php tutorials

PHP Database Class to access Mysql

This is a simple class that evolved out of the php code I wrote so far. It has the following functions : 1. dbms() - The constructor to do the initialisation like connecting to the database etc. 2. query($query) - The method to take a sql string and perform the query. 3. close() - Close the database connection 4. backup() - Create a backup of ...

Restore Mysql Database from a sql or zip file using PHP

In a previous post we learnt how to inside php. In this example the same zip file would be used to restore the database. Code // Function to restore from a file function restore($path) { $f = fopen('restore/temp.sql' , 'w+'); if(!$f) { echo "Error While Restoring Database"; return; } $zip = new ZipArchive(); ...

Backup mysql database with php and zip it

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 command shall dump the database named $db_name ...

Php – parse text and convert urls into hyperlinks

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 href="http://$1">$1</a>', $str); $str = preg_replace('/((+)(.+)*@(+.)+{2,6})/', '<a href="mailto:$1">$1</a>', $str); ...

Run php scripts from cron

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 maintenance or administration, taking backups or ...

Php set_time_limit wont take into account socket operations

The PHP function set_time_limit is used to set a time limit on the maximum execution time of a script. But if the script has socket operations using fsockopen , fread and fwrite or even CURL then the set_time_limit may not appear to have any effect on the scripts timelimit or timeout. Again if safe mode is on then also set_time_limit has ...

Get real IP address of user in php

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 variable $_SERVER. Here is a quick example //Get ...

Remote Login with Curl PHP

Remote login with CURL The curl extension of php can be used to open remote webpages by both GET and POST methods. There are many situations when you need a php script to login into a website and open a certain page. For example when you are writing a bot or web scraper. To login we need 2 important piece of information ...

Create excel files in php – simple and easy way

Database applications written in php often need to export data for reporting purpose. A popular export format is excel. Excel is a spreadsheet that lays out data in a grid format. Excel itself is a microsoft proprietory format. There are many libraries available for php like Spreadsheet_Excel_Writer pear package etc that can do the job. However these libraries need to ...

Pages:«123456789


Connect with us