Category: PHP

Php Tutorials

Php Display only number of characters from string

Php Display only number of characters from string

  This is an example to display only 13 characters from a string: $string = (strlen($string) > 13) ? substr($string,0,10).’…’ : $string;

Accessing a URL protected by htpasswd (Basic Auth) with php

Accessing a URL protected by htpasswd (Basic Auth) with php

It is possible to access a URL protected by htpasswd with Basic Authentication through php scripts. Here is an example : <?php $url=”url to access”; $https_user=””; $https_password=””; $opts = array(‘http’ => array( ‘method’ =>...

Installing PHP Time Zone Database

Installing PHP Time Zone Database

Instead of relying on system time zone database, you can use php timezone database which gets updated more frequently. Here is how to do that : pecl install timezonedb If you do not have...

Apache – Disable script execution upload directory

Apache – Disable script execution upload directory

For Apache: <Directory /path/to/directory>  php_flag engine off </Directory> For Nginx : location  /path/to/directory/ { location ~ .*\.(php)?$ {   deny all; } }

php tips and tricks

php tips and tricks

Php Tweaks, settings and tricks   Php Set display Error for a specific page: To display errors for a specific page, set this on the top of the php page: ini_set(‘display_errors’, 1); ini_set(‘log_errors’, 1);...

write to a file using php

write to a file using php

$myFile = “testFile.txt”; $fh = fopen($myFile, ‘a’) or die(“can’t open file”); $stringData = “New Stuff 1\n”; fwrite($fh, $stringData); $stringData = “New Stuff 2\n”; fwrite($fh, $stringData); fclose($fh);

Php Session Timeout

Php Session Timeout

Creating an activity timeout using php:  function check_session() { if (isset($_SESSION[‘last_active’]) && (time() – $_SESSION[‘last_active’] > 300)) { // last request was more than 30 minates ago /*                          ...

PHP basic compile options when buidling from source

PHP basic compile options when buidling from source

  ./configure  –prefix=/usr –sysconfdir=/etc –with-config-file-path=/etc/ –localstatedir=/var –with-apxs2 –with-openssl –with-zlib –enable-calendar –with-gd –with-jpeg-dir=/usr/lib –with-png-dir=/usr/lib –with-imap –with-imap-ssl –with-kerberos –enable-sysvsem –enable-sysvshm –enable-sockets –with-curl –enable-mbstring –with-mcrypt –with-mysql –with-mysqli –with-gettext –with-freetype-dir –enable-gd-native-ttf