ecco come la invoco:

Codice PHP:
require_once("../include/db.php");
mysql_select_db($db2,$dbconn) or die (mysql_error()." errore selezione $db2");

function 
idshopping(){
        
$idshopping="";
        for(
$x=1;$x<=20;$x++){
            
$idshopping.=rand(0,9);
        }
        
        
$QueryVer=mysql_query("SELECT IDShopping FROm cart WHERE IDShopping='$idshopping'") or die (mysql_error()." errore verifica idshopping in cart");
        if(
mysql_num_rows($QueryVer) > 0){
            
idshopping();
        }else{
            
$QueryVer=mysql_query("SELECT IDShopping FROm shopping WHERE IDShopping='$idshopping'") or die (mysql_error()." errore verifica idshopping in shopping");
            if(
mysql_num_rows($QueryVer) > 0){
                
idshopping();
            }else{
                
$time=(3600 24 365);
                
setcookie("IDShopping_CS",$idshopping,time() + $time,"/");
                return 
$idshopping;
            }
        }
        
mysql_free_result($QueryVer);
}

(!isset(
$_COOKIE["IDShopping_CS"])) ? $idshopping=idshopping() : $idshopping=$_COOKIE["IDShopping_CS"];
...