Category: PHP

Run Webserver with current folder as root

Different ways to run a webserver using the current directory as root. Useful to serve static files.

Random Password in PHP

A simple way to create a random password in PHP $password = substr(md5(time()), 0, rand(4,8));

Force Download Dialog with PHP using octect-stream

Use this code to force a download of any type of content with PHP header(“Content-type:application/octect-stream”); header(‘Content-Disposition: attachment; filename=filename_’ . date(‘Y-m-d’)…

Compress PHP Output from .htaccess

Compress all PHP output by adding this line to .htaccess file php_value output_handler ob_gzhandler

301 Redirect using PHP

301 Redirect using PHP header (‘HTTP/1.1 301 Moved Permanently’); header (‘Location: ‘.$new_location);

CSV Export/Import Functions in PHP

Functions to Export and import CSV data using PHP //*Get the result of the query as a CSV stream. function…

HTTP Digest Authentication with PHP

The code for using HTTP Digest Authentication with PHP. <?php realm = ‘Restricted area’; if (empty(_SERVER[‘PHP_AUTH_DIGEST’])) { header(‘HTTP/1.1 401 Unauthorized’);…

Searching text in a directory using find and grep

Use find and grep to search for a specific text in a directory. In this example, we search for files…

Find Difference Between 2 Dates in PHP

This function will find the difference between two given times. Does PHP already have a native function for that? //The…

Using PHP’s Curl functions behind a Proxy

Using PHP’s Curl functions even if the net is accessible only thru a proxy. This is the only way curl…