Saturday, August 04, 2007

Four ways to generate unique id by PHP

1. Using uniqid() function

<?php

//creates a unique id with the 'about' prefix
$a uniqid(about);
echo 
$a;
echo 
"<br>";

//creates a longer unique id with the 'about' prefix
$b uniqid (abouttrue);
echo 
$b;
echo 
"<br>";

//creates a unique ID with a random number as a prefix - more secure than a static prefix 
$c uniqid (rand(), true);
echo 
$c;
echo 
"<br>";

//this md5 encrypts the username from above, so its ready to be stored in your database
$md5c md5($c);
echo 
$md5c;
echo 
"<br>";

?>

2. Using current time + IP style

<?php

//You can also use $stamp = strtotime ("now"); But I think date("Ymdhis") is easier to understand.
$stamp date("Ymdhis");
$ip $_SERVER['REMOTE_ADDR'];
$orderid "$stamp-$ip";
$orderid str_replace(".""""$orderid");
echo(
$orderid);
echo 
"<br>";

?>

3. Generate custom length unique id

<?php

//set the random id length 
$random_id_length 10

//generate a random id encrypt it and store it in $rnd_id 
$rnd_id crypt(uniqid(rand(),1)); 

//to remove any slashes that might have come 
$rnd_id strip_tags(stripslashes($rnd_id)); 

//Removing any . or / and reversing the string 
$rnd_id str_replace(".","",$rnd_id); 
$rnd_id strrev(str_replace("/","",$rnd_id)); 

//finally I take the first 10 characters from the $rnd_id 
$rnd_id substr($rnd_id,0,$random_id_length); 

echo 
"Random Id: $rnd_id" ;
echo 
"<br>";

?>

4. Generate XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX style unique id, (8 letters)-(4 letters)-(4 letters)-(4 letters)-(12 letters)

<?php

// Generate Guid 
function NewGuid() { 
    
$s strtoupper(md5(uniqid(rand(),true))); 
    
$guidText 
        
substr($s,0,8) . '-' 
        
substr($s,8,4) . '-' 
        
substr($s,12,4). '-' 
        
substr($s,16,4). '-' 
        
substr($s,20); 
    return 
$guidText;
}
// End Generate Guid 

$Guid NewGuid();
echo 
$Guid;
echo 
"<br>";

?>

Friday, August 03, 2007

reach out to sb...

reach out to sb (mainly US) = to try to communicate with a person or a group of people, usually in order to help or involve them eg The new mayor is reaching out to the local community to involve them in his plans for the city.

Wednesday, August 01, 2007

Do you need a beautiful email icon?


While I am surfing on the web today, I found a site can easily generate Email icon according to your Email service provider. Very funny...
They accept almost every commonly used email service provider. What make me astonished is that QQ.com is listed. It's an IM that very commonly used in China. Almost everyone that surfs the web has a QQ number.
You can have your own email icon put on your blogs or your own websites.
Have fun...

Saturday, March 24, 2007

Link Building Tips and Optimize the Site

-offer a poll on your blog-offer a contests on you website

-create a interactive tool dealing with your products online

-write controversial or newsworthy content

-offer resourceful content-offer humorous content

-give something away for free

-create widgets