Thursday, September 6, 2012

Fighting with old code

Some people prefer to use old outdated scripts even if there are good modern alternatives are available. Such code can be is very dangerous from security standpoint. Nevertheless, reasonable sense does not work for them. Today we had to fix issue with the MultiCart (http://www.iscripts.com/multicart/) script which uses session_register() function to work with sessions. The problem is that this function is not available in PHP 5.4.
Here is a quick fix to this problem (the code below should be inserted into the module with common functions which is loaded by all other scripts).

if(!function_exists('session_is_registered')){
     function session_is_registered($varname)
     {
        return isset($_SESSION[$varname]);
     }
}

if(!function_exists('session_unregister')){
     function session_unregister($varname)
     {
        if(session_is_registered($varname])){
            unset($_SESSION[$varname];
        }
     }
}

if(!function_exists('session_register')) {  
     function session_register() {
        $arguments = funct_get_args();
        if(empty($arguments)){
            return false;
        }
        
        foreach($arguments as $varname){
            if(isset($GLOBALS[$varname])){ 
                $_SESSION[$varname] = $GLOBALS[$varname]; 
            }
        }
        
        return false;
     }
}

No comments:

Post a Comment

Popular Posts