Skip to main content

Posts

PHP Function to calculate time remaining

Many times it is required for us to calculate the time remaining and display it in a very understandable format like days,weeks,hours etc. Here is a function i wrote to do the same. PHP Code: //FUNCTION FOR TIME LEFT function time_left($integer) { $seconds=$integer; if ($seconds/60 >=1) { $minutes=floor($seconds/60); if ($minutes/60 >= 1) { # Hours $hours=floor($minutes/60); if ($hours/24 >= 1) { #days $days=floor($hours/24); if ($days/7 >=1) { #weeks $weeks=floor($days/7); if ($weeks>=2) $return="$weeks Weeks"; else $return="$weeks Week"; } #end of weeks $days=$days-(floor($days/7))*7; if ($weeks>=1 && $days >=1) $return="$return, "; if ($days >=2) $return="$return $days days"; if ($days ==1) $return="$return $days day"; } #end of ...

Install/Run PHP4 and PHP5 Together

If you have PHP4 working on your server, and have heard that PHP5 may screw up things. Here's how to have both running alongside. Code: PHP #!/bin/sh # PHP5 CGI Installer for cPanel/WHM Servers VERSION=5.0.4 cd /usr/src wget -O php.tbz2 "http://us4.php.net/get/php-${VERSION}.tar.bz2/from/this/mirror" tar -xjvf php.tbz2 rm -f php.tbz2 wget http://choon.net/opensource/php/php-${VERSION}-mail-header.patch cd php-${VERSION} patch -p1 } —prefix=/usr/local/php5 —exec-prefix=/usr/local/php5 —program-suffix=5 —enable-force-cgi-redirect —enable-discard-path" ./configure $CFGLINE make make install cp -f php.ini-recommended /usr/local/php5/lib/php.ini cp /usr/local/php5/bin/php5 /usr/local/cpanel/cgi-sys/php5 chown root:wheel /usr/local/cpanel/cgi-sys/php5 echo "Action application/x-httpd-php5 "/cgi-sys/php5"" > /usr/local/apache/conf/php5.conf echo "AddType application/x-httpd-php5 .php5" >> ...

File Version Management in PHP

Management of files Manipulating files is a basic necessity for programmers and PHP gives you a great deal of tools for creating, uploading, and editing files. When you are manipulating files you must be very careful because you can do a lot of damage if you do some errors. Common errors include editing the wrong file, filling a hard-drive with garbage data, and accidentally deleting a file's contents. Before you can do anything with a file it has to exist! So we need to create file in PHP. Creating files in PHP The fopen function needs two important pieces of information to operate correctly. First, we must supply it with the name of the file that we want it to open. Secondly, we must tell the function what we plan on doing with that file . Since we want to create a file, we must supply a file name and tell PHP that we want to write to the file. Note: We have to tell PHP we are writing to the file, otherwise it will not create a new file. Code: PHP $ourFileName = ...

Google Image Leecher - Php Code

This Code let you take a image search on Google easily and user-friendly. You can pre-specify image properties: image name or caption, size and dimension rank of image. Code Here: PHP Code: Google Image Leecher Coder: o0DarkEvil0o Search For Max width Max height Min width Min height "> "> "> "> "> Image Link Dimesion Image Size ' ); $s2=array(' ',' '); function getResult($str,$hash) { $p=array(); $p[0]=strpos($str,$hash[0]); $p[1]=strpos($str,$hash[1],$p[0]); return substr($str,$p[0],$p[1]-$p[0]); } function CutL...

Creating image thumbnails with PHP!

If we intend to make an image gallery, and we would like to show the thumbails of the images, it wouldn't be a wise idea to show the original images with their height & width modified in the tag, that would result in low image quality & higher download time. The solution to this problem would be creating thumbnails at the server end and display them instead. This solution can be approached in two ways, you can create the thumbnails once and for all or create thumbnails everytime at runtime. For this purpose, I wrote a class which will create the thumbnail. The class: PHP Code: /* * File : thumb.class.php * Description : Class for creating thumbnails */ class Thumb { var $filename; var $img; var $height; var $width; var $ratio = 10; var $oldim; var $oldh; var $oldw; function filename($file) /* used for setting filename */ { $this->filename = $file; } ...

Why use PHP for server-side scripting?

A trend with a lot of new Web Designers is to blindly go for ASP or JSP for creating dynamic and interactive websites. Why use PHP for server-side scripting? This question comes in mind of a lot of Web Designers, especially in mind of designers/programmers who are only exposed to much hyped server side scripting languages such as ASP or JSP. PHP is indeed a great choice for dynamic websites and a lot of popular websites do use PHP as a scripting language. A lot of designers shy away from a good web hosting providers such as Yahoo as it does not support JSP but supports PHP! In this discussion I want to bring into light why use PHP for server-side scripting when there is ASP and JSP around. What is PHP? PHP is a server-side scripting language, such as ASP and JSP. PHP is an open source and free to download and use. It is a powerful scripting language for creating dynamic and interactive websites. PHP files may contain text, HTML tags and scripts. PHP files have a file extension of...

How to Make Your Own PHP Captcha Generator

In this article we will create file based simple yet successful captcha generator. 3 Major Anti-spamming techniques used? Mathematical Operation like Random number + Random Number = -> The user must specify the answer Random word -> User must type the word Random question -> Obvious one which the user should answer correctly [ex: Are you human?] How Captcha works? The captcha generator generates an IMAGE with the question and then put up a session variable storing the value. User input though an input box. Using php POST, we compare the session variable data with the user input and tell whether its a bot or human. Its coding time The Code First let's write the php script which generates the captcha image. We use the simple header-content change technique, from which we can easily bring up an image from a given text. captcha.php PHP Code: array("Num" => "Num"), 1 => array("Are y...