September 2011 archive

PHP characters limitation

Characters limitation will helps to display limited number of characters to display. [php] function limit_characters( $str, $n ) { if ( strlen ( $str ) <= $n ) { return $str; } else { return substr ( $str, 0, $n ) . ‘…’; } } [/php]

Permanent link to this article: https://blog.openshell.in/2011/09/php-characters-limitation/

Resize image in specified height & width while upload

Resizing images in specified height & width while uploading files to the server. [php] /* Create a thumbnail of $srcFile and save it to $destFile. The thumbnail will be $width pixels. */ function createThumbnail($srcFile, $destFile, $new_w, $new_h, $quality = 75) { $thumbnail = ”; if (file_exists($srcFile) && isset($destFile)) { $size = getimagesize($srcFile); $old_x = $size[0]; …

Continue reading

Permanent link to this article: https://blog.openshell.in/2011/09/resize-image-in-specified-height-width-while-upload/

PHP Automatic Session Logout

Automatic logout script if users have inactive more than 15 minutes [php] <?php session_start(); $inactive = 900; // Set timeout period in seconds if (isset($_SESSION[‘timeout’])) { $session_life = time() – $_SESSION[‘timeout’]; if ($session_life > $inactive) { session_destroy(); header("Location: logoutpage.php"); } } $_SESSION[‘timeout’] = time(); ?> [/php]

Permanent link to this article: https://blog.openshell.in/2011/09/php-automatic-session-logout/

PHP MYSQL ORDER BY Multiple Columns

If you want to Order 2 or more columns in SQL Query. When ordering by more than one column, the second column is only used if the values are identical with the onces in the first column. Example [sql] ‘Order by Column ORDER BY COLUMN1, COLUMN2 [/sql] Order 2 or more columns with different orders …

Continue reading

Permanent link to this article: https://blog.openshell.in/2011/09/php-mysql-order-by-multiple-columns/