Tag: PHP

Install LAMP Stack on Ubuntu/Debian

Install LAMP Stack on Ubuntu/Debian using apt-get sudo apt-get install openssh-server openssh-client apache2 libapache2-mod-php5 php5-cli php5-common php5-cgi mysql-client mysql-common mysql-server…

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…

Compile and Install LAMP Server from Source – PHP5, Apache2, MySQL5

MySQL ./configure –prefix=/usr/local/mysql –localstatedir=/var/lib/mysql –with-mysqld-user=mysql –with-unix-socket-path=/tmp/mysql.sock –without-comment –without-debug –without-bench make make install cp support-files/my-medium.cnf /etc/my.cnf chown root:sys /etc/my.cnf chmod 644…

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…