Luhn algorithm for IMEI Check
public function __checkIMEI($imei){
if(strlen($imei)==15){
$imeia=($imei[1]*2);
if(strlen($imeia)==2){$imeia=str_split($imeia,1); $imeia=$imeia[0]+$imeia[1]; }
$imeib=($imei[3]*2);
if(strlen($imeib)==2){$imeib=str_split($imeib,1); $imeib=$imeib[0]+$imeib[1]; }
$imeic=($imei[5]*2);
if(strlen($imeic)==2){$imeic=str_split($imeic,1); $imeic=$imeic[0]+$imeic[1]; }
$imeid=($imei[7]*2);
if(strlen($imeid)==2){$imeid=str_split($imeid,1); $imeid=$imeid[0]+$imeid[1];}
$imeie=($imei[9]*2);
if(strlen($imeie)==2){$imeie=str_split($imeie,1); $imeie=$imeie[0]+$imeie[1]; }
$imeif=($imei[11]*2);
if(strlen($imeif)==2){$imeif=str_split($imeif,1); $imeif=$imeif[0]+$imeif[1]; }
$imeig=($imei[13]*2);
if(strlen($imeig)==2){$imeig=str_split($imeig,1); $imeig=$imeig[0]+$imeig[1]; }
$IMEI=
($imei[0]+$imeia+$imei[2]+$imeib+$imei[4]+$imeic+$imei[6]+$imeid+$imei[8]
+$imeie+$imei[10]+$imeif+$imei[12]+$imeig);
$IMEI=($IMEI%10);
if($IMEI!=0){
$IMEI=10-$IMEI;
}
if($IMEI!=0){
$IMEI=10-$IMEI;
}
if($IMEI==$imei[14]){
return true;
}else{
return true;
}
}else{
return false;
}
There are many magic methods in PHP like __construct(), __destruct(), __callback(), __get(), __set(), __sleep(), __wake() and many more. But we will be takingon on __sleep() and __wake(). __sleep() : serialize() checks if your class has a function with the magic name __sleep(). If so, that function is executed prior to any serialization. It can clean up the object and is supposed to return an array with the names of all variables of that object that should be serialized. If the method doesn't return anything then NULL is serialized and E_NOTICE is issued. serialize() is used for the representation of the storage class for storing the value. Serializing an object means converting it to a byte stream representation that can be stored in a file. The use of __sleep() to commit the pending task. If a bulk data is being inserted then at that time __sleep can be used. it will not release the object unless the work is not completed....
Good Work
ReplyDeleteThanks !!
DeleteWe will love to see you again !!