Saturday, July 31, 2010

Check Domain availability Using PHP

How to Check Domain Availability using PHP


<?php

function checkDomainAvailability($domain_name){

$server = 'whois.crsnic.net';

// Open a socket connection to the whois server
$connection = fsockopen($server, 43);
if (!$connection) return false;

// Send the requested doman name
fputs($connection, $domain_name."\r\n");

// Read and store the server response
$response_text = ' :';
while(!feof($connection)) {
$response_text .= fgets($connection,128);
}

// Close the connection
fclose($connection);

// Check the response stream whether the domain is available
if (strpos($response_text, 'No match for')) return true;
else return false;
}


$domainname = 'anilbuddha.com';

if(checkDomainAvailability($domainname)) echo 'Domain : '.$domainname.' is Available';
else echo 'Domain : '.$domainname.' is Already Taken';

?>

Wishing all my Friends a Happy Friendship Day



Friendship is not about finding similarities, it is about respecting differences. You are not my friend coz you are like me, but because i accept you and respect you the way you are. 

Wishing All my Friends a Happy Friendship Day......

Tuesday, July 27, 2010

Download DonSeenu Songs

Download the latest Songs of Don Seenu

Starring Ravi teja, Shreya saran.



For Download, Click Here

Source: southmp3.net 

Gmail Type Chat using PHP & Jquery

Need Gmail type chat using PHP & Jquery....

Here is the applicaion, download the file here.

For file download, click here

Saturday, July 24, 2010

Epic Browser Done By Indians

Download latest Browser done by Indians, EPIC BROWSER........

For download, Click here

Resize Image using PHP

Problem to resize a big image while uploading using PHP, here is the code for resizing the image using a simple class. To download the file, Click here

The Class For resizing an image is shown  below.

Class resize
        {
            // *** Class variables
            private $image;
            private $width;
            private $height;
            private $imageResized;

            function __construct($fileName)
            {
                // *** Open up the file
                $this->image = $this->openImage($fileName);

                // *** Get width and height
                $this->width  = imagesx($this->image);
                $this->height = imagesy($this->image);
            }

            ## --------------------------------------------------------

            private function openImage($file)
            {
                // *** Get extension
                $extension = strtolower(strrchr($file, '.'));

                switch($extension)
                {
                    case '.jpg':
                    case '.jpeg':
                        $img = @imagecreatefromjpeg($file);
                        break;
                    case '.gif':
                        $img = @imagecreatefromgif($file);
                        break;
                    case '.png':
                        $img = @imagecreatefrompng($file);
                        break;
                    default:
                        $img = false;
                        break;
                }
                return $img;
            }

            ## --------------------------------------------------------

            public function resizeImage($newWidth, $newHeight, $option="auto")
            {
                // *** Get optimal width and height - based on $option
                $optionArray = $this->getDimensions($newWidth, $newHeight, $option);

                $optimalWidth  = $optionArray['optimalWidth'];
                $optimalHeight = $optionArray['optimalHeight'];


                // *** Resample - create image canvas of x, y size
                $this->imageResized = imagecreatetruecolor($optimalWidth, $optimalHeight);
                imagecopyresampled($this->imageResized, $this->image, 0, 0, 0, 0, $optimalWidth, $optimalHeight, $this->width, $this->height);


                // *** if option is 'crop', then crop too
                if ($option == 'crop') {
                    $this->crop($optimalWidth, $optimalHeight, $newWidth, $newHeight);
                }
            }

            ## --------------------------------------------------------
           
            private function getDimensions($newWidth, $newHeight, $option)
            {

               switch ($option)
                {
                    case 'exact':
                        $optimalWidth = $newWidth;
                        $optimalHeight= $newHeight;
                        break;
                    case 'portrait':
                        $optimalWidth = $this->getSizeByFixedHeight($newHeight);
                        $optimalHeight= $newHeight;
                        break;
                    case 'landscape':
                        $optimalWidth = $newWidth;
                        $optimalHeight= $this->getSizeByFixedWidth($newWidth);
                        break;
                    case 'auto':
                        $optionArray = $this->getSizeByAuto($newWidth, $newHeight);
                        $optimalWidth = $optionArray['optimalWidth'];
                        $optimalHeight = $optionArray['optimalHeight'];
                        break;
                    case 'crop':
                        $optionArray = $this->getOptimalCrop($newWidth, $newHeight);
                        $optimalWidth = $optionArray['optimalWidth'];
                        $optimalHeight = $optionArray['optimalHeight'];
                        break;
                }
                return array('optimalWidth' => $optimalWidth, 'optimalHeight' => $optimalHeight);
            }

            ## --------------------------------------------------------

            private function getSizeByFixedHeight($newHeight)
            {
                $ratio = $this->width / $this->height;
                $newWidth = $newHeight * $ratio;
                return $newWidth;
            }

            private function getSizeByFixedWidth($newWidth)
            {
                $ratio = $this->height / $this->width;
                $newHeight = $newWidth * $ratio;
                return $newHeight;
            }

            private function getSizeByAuto($newWidth, $newHeight)
            {
                if ($this->height < $this->width)
                // *** Image to be resized is wider (landscape)
                {
                    $optimalWidth = $newWidth;
                    $optimalHeight= $this->getSizeByFixedWidth($newWidth);
                }
                elseif ($this->height > $this->width)
                // *** Image to be resized is taller (portrait)
                {
                    $optimalWidth = $this->getSizeByFixedHeight($newHeight);
                    $optimalHeight= $newHeight;
                }
                else
                // *** Image to be resizerd is a square
                {
                    if ($newHeight < $newWidth) {
                        $optimalWidth = $newWidth;
                        $optimalHeight= $this->getSizeByFixedWidth($newWidth);
                    } else if ($newHeight > $newWidth) {
                        $optimalWidth = $this->getSizeByFixedHeight($newHeight);
                        $optimalHeight= $newHeight;
                    } else {
                        // *** Sqaure being resized to a square
                        $optimalWidth = $newWidth;
                        $optimalHeight= $newHeight;
                    }
                }

                return array('optimalWidth' => $optimalWidth, 'optimalHeight' => $optimalHeight);
            }

            ## --------------------------------------------------------

            private function getOptimalCrop($newWidth, $newHeight)
            {

                $heightRatio = $this->height / $newHeight;
                $widthRatio  = $this->width /  $newWidth;

                if ($heightRatio < $widthRatio) {
                    $optimalRatio = $heightRatio;
                } else {
                    $optimalRatio = $widthRatio;
                }

                $optimalHeight = $this->height / $optimalRatio;
                $optimalWidth  = $this->width  / $optimalRatio;

                return array('optimalWidth' => $optimalWidth, 'optimalHeight' => $optimalHeight);
            }

            ## --------------------------------------------------------

            private function crop($optimalWidth, $optimalHeight, $newWidth, $newHeight)
            {
                // *** Find center - this will be used for the crop
                $cropStartX = ( $optimalWidth / 2) - ( $newWidth /2 );
                $cropStartY = ( $optimalHeight/ 2) - ( $newHeight/2 );

                $crop = $this->imageResized;
                //imagedestroy($this->imageResized);

                // *** Now crop from center to exact requested size
                $this->imageResized = imagecreatetruecolor($newWidth , $newHeight);
                imagecopyresampled($this->imageResized, $crop , 0, 0, $cropStartX, $cropStartY, $newWidth, $newHeight , $newWidth, $newHeight);
            }

            ## --------------------------------------------------------

            public function saveImage($savePath, $imageQuality="100")
            {
                // *** Get extension
                $extension = strrchr($savePath, '.');
                   $extension = strtolower($extension);

                switch($extension)
                {
                    case '.jpg':
                    case '.jpeg':
                        if (imagetypes() & IMG_JPG) {
                            imagejpeg($this->imageResized, $savePath, $imageQuality);
                        }
                        break;

                    case '.gif':
                        if (imagetypes() & IMG_GIF) {
                            imagegif($this->imageResized, $savePath);
                        }
                        break;

                    case '.png':
                        // *** Scale quality from 0-100 to 0-9
                        $scaleQuality = round(($imageQuality/100) * 9);

                        // *** Invert quality setting as 0 is best, not 9
                        $invertScaleQuality = 9 - $scaleQuality;

                        if (imagetypes() & IMG_PNG) {
                             imagepng($this->imageResized, $savePath, $invertScaleQuality);
                        }
                        break;

                    // ... etc

                    default:
                        // *** No extension - No save.
                        break;
                }

                imagedestroy($this->imageResized);
            }


            ## --------------------------------------------------------

        }

Paypal Integration

How to Integrate with Paypal for our application is shown below.


<form method='post' action='https://www.paypal.com/cgi-bin/webscr' id="test">   
         
           <input type="hidden" name="cmd" value="_xclick" />
           <input type="hidden" name="business" value="businessaccount@mail.com" />
           <input type="hidden" name="cbt" value="* * * Return to Bearmanor Media Bizland * * *">     
           <input type="hidden" name="item_name" value="{ item_name }" /><!--change the { item name } give the item name which you want to show on paypal  -->
           <input type="hidden" name="amount" value="{total_amount_}" /><!--change the {total_amount_} give the total amount which you want to show on paypal -->
           <input type="hidden" name="no_shipping" value="1" />
           <input type="hidden" name="rm" value="2">
           <input type="hidden" name="return" value="{return url}" /><!--change the {return url} give the url to which it should redirect after completing the payment -->
           <input type="hidden" name="cpp_header_image" value="{bannerimage}" /><!--change the {bannerimage} give the url of banner if you have otherwise change it to empty such as value=""  -->
     <input type="hidden" name="notify_url" value="">          
           <input type="hidden" name="currency_code" value="USD" />          
           <input type="hidden" name="custom" value="{order_id}" /> 
  
           <input type="hidden" name="cancel_return" value="{Cancel page(Ex:-http://www.mysite.com/CancelPayment.php}" />     
           <input type="image" id='submit' src="paynow.jpg" border="0" alt="Make payments with PayPal - it's fast, free and secure!" />
        
           
     </form>

Tuesday, July 20, 2010

Showing Current Date & Time using Javascript

Insert the Below code anywhere into the body section where you need to see the Current date & time 

<script>

var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
var montharray=new Array("January","February","March","April","May","June","July","August","September","October","November","December")

function getthedate(){
var mydate=new Date()
var year=mydate.getYear()
if (year < 1000)
year+=1900
var day=mydate.getDay()
var month=mydate.getMonth()
var daym=mydate.getDate()
if (daym<10)
daym="0"+daym
var hours=mydate.getHours()
var minutes=mydate.getMinutes()
var seconds=mydate.getSeconds()
var dn="AM"
if (hours>=12)
dn="PM"
if (hours>12){
hours=hours-12
}
if (hours==0)
hours=12
if (minutes<=9)
minutes="0"+minutes
if (seconds<=9)
seconds="0"+seconds
//change font size here
var cdate="<small><font color='000000' face='Arial'><b>"+dayarray[day]+", "+montharray[month]+" "+daym+", "+year+" "+hours+":"+minutes+":"+seconds+" "+dn
+"</b></font></small>"
if (document.all)
document.all.clock.innerHTML=cdate
else if (document.getElementById)
document.getElementById("clock").innerHTML=cdate
else
document.write(cdate)
}
if (!document.all&&!document.getElementById)
getthedate()
function goforit(){
if (document.all||document.getElementById)
setInterval("getthedate()",1000)
}

</script>
<span id="clock"></span>

& in the Body tag, we need to add an onLoad Function as shown below.

<body onload="goforit()">

For more Scripts...visit dynamicdrive

Sunday, July 18, 2010

Loading Image Before the Page Loads using Javascript

Below is the code used to show the Loading image before the page loads.


To implement this you will need to:

1. Every time your page loads a "init()" function will load.

<body onLoad="init()">

2. Define a div named "loading" right after <body> section.

<div id="loading" style="position:absolute; width:100%; text-align:center; top:300px;">
<img src="loading.gif" border=0></div>
 
The loading.gif image should be an animated gif that suggests that the page is still loading.

3. Place this javascript code right after you define the div.
 <script>
 var ld=(document.all);
  var ns4=document.layers;
 var ns6=document.getElementById&&!document.all;
 var ie4=document.all;
  if (ns4)
  ld=document.loading;
 else if (ns6)
  ld=document.getElementById("loading").style;
 else if (ie4)
  ld=document.all.loading.style;
  function init()
 {
 if(ns4){ld.visibility="hidden";}
 else if (ns6||ie4) ld.display="none";
 }
 </script>
 
& to See the Demo, Click Here 

Sunday, July 11, 2010

PHP Interview Questions

Why doesn’t the following code print the newline properly? <?php $str = ‘Hello, there.\nHow are you?\nThanks for visiting myblog’; print $str; ?>
Because inside the single quotes the \n character is not interpreted as newline, just as a sequence of two characters - \ and n.

Would you initialize your strings with single quotes or double quotes?
Since the data inside the single-quoted string is not parsed for variable substitution, it’s always a better idea speed-wise to initialize a string with single quotes, unless you specifically need variable substitution.

How can we extract string 'abc.com ' from a string http://info@abc.com using regular expression of php?
 We can use the preg_match() function with "/.*@(.*)$/" as
the regular expression pattern. For example:
preg_match("/.*@(.*)$/","http://info@abc.com",$data);
echo $data[1];

What are the differences between GET and POST methods in form submitting, give the case where we can use GET and we can use POST methods?
Anwser 1:

When we submit a form, which has the GET method it displays pair of name/value used in the form at the address bar of the browser preceded by url. Post method doesn't display these values.

Anwser 2:

When you want to send short or small data, not containing ASCII characters, then you can use GET” Method. But for long data sending, say more then 100 character you can use POST method.

Once most important difference is when you are sending the form with GET method. You can see the output which you are sending in the address bar. Whereas if you send the form with POST” method then user can not see that information.

Anwser 3:

What are "GET" and "POST"?

GET and POST are methods used to send data to the server: With the GET method, the browser appends the data onto the URL. With the Post method, the data is sent as "standard input."

Major Difference

In simple words, in POST method data is sent by standard input (nothing shown in URL when posting while in GET method data is sent through query string.

Ex: Assume we are logging in with username and password.

GET: we are submitting a form to login.php, when we do submit or similar action, values are sent through visible query string (notice ./login.php?username=...&password=... as URL when executing the script login.php) and is retrieved by login.php by $_GET['username'] and $_GET['password'].

POST: we are submitting a form to login.php, when we do submit or similar action, values are sent through invisible standard input (notice ./login.php) and is retrieved by login.php by $_POST['username'] and $_POST['password'].

POST is assumed more secure and we can send lot more data than that of GET method is limited (they say Internet Explorer can take care of maximum 2083 character as a query string).

Anwser 4:

In the get method the data made available to the action page ( where data is received ) by the URL so data can be seen in the address bar. Not advisable if you are sending login info like password etc. In the post method the data will be available as data blocks and not as query string in case of get method.

Anwser 5:

When we submit a form, which has the GET method it pass value in the form of query string (set of name/value pair) and display along with URL. With GET we can a small data submit from the form (a set of 255 character) whereas Post method doesn't display value with URL. It passes value in the form of Object and we can submit large data from the form.

Anwser 6:

On the server side, the main difference between GET and POST is where the submitted is stored. The $_GET array stores data submitted by the GET method. The $_POST array stores data submitted by the POST method.
On the browser side, the difference is that data submitted by the GET method will be displayed in the browser’s address field. Data submitted by the POST method will not be displayed anywhere on the browser.
GET method is mostly used for submitting a small amount and less sensitive data. POST method is mostly used for submitting a large amount or sensitive data.

What is the difference between the functions unlink and unset?
unlink() is a function for file system handling. It will simply delete the file in context.

unset() is a function for variable management. It will make a variable undefined.

How come the code works, but doesn’t for two-dimensional array of mine?
Any time you have an array with more than one dimension, complex parsing syntax is required. print "Contents: {$arr[1][2]}" would’ve worked.

For More Interview Questions, Click Here