Location: PHPKode > projects > MembersGear > membersgear/installation/functions.php
<?php 
  
 function is__writable($path) {

        if ($path{strlen($path)-1}=='/')
            return is__writable($path.uniqid(mt_rand()).'.tmp');

        if (file_exists($path)) {
            if (!($f = @fopen($path, 'r+')))
                return false;
            fclose($f);
            return true;
        }

        if (!($f = @fopen($path, 'w')))
            return false;
        fclose($f);
        unlink($path);
        return true;
}



    function Redirect($pUrl='', $pEndResponse=false)
    {     
        if(trim($pUrl)=='')
            return false;
            
        echo("<script language='javascript'>\n" .
                "window.location.href='".$pUrl."'\n" .
             "</script>");  
             
        if($pEndResponse) die;
        
        return false;     
    }
    
    
    //Project007Bond
    function encrypt($string,$pkey='MEMBERSITEENCRYPTEDKEY') {
        $key = $pkey;
        if(!isset($key) or $key=="")
            $key='MEMBERSITEENCRYPTEDKEY'; 
        $result = '';
        for($i=0; $i<strlen($string); $i++) {
             $char = substr($string, $i, 1);
             $keychar = substr($key, ($i % strlen($key))-1, 1);
             $char = chr(ord($char)+ord($keychar));
             $result.=$char;
         }
         
       $skey=urlencode(base64_encode($result));
       
       return $skey;
  }
  function decrypt($string,$pkey='MEMBERSITEENCRYPTEDKEY') {
        $key = $pkey;
        if(!isset($key) or  $key=="")           
              $key='MEMBERSITEENCRYPTEDKEY';
        $result = '';
        $string = base64_decode(urldecode($string));
       for($i=0; $i<strlen($string); $i++) {
             $char = substr($string, $i, 1);
             $keychar = substr($key, ($i % strlen($key))-1, 1);
             $char = chr(ord($char)-ord($keychar));
             $result.=$char;
         }
       return $result;
  }
  
  function createToken()
  {
    // Declare salt and prefix
    $token.='Z007MEMBERAREA';
    $sections=5;
    $sectionlength=5;
    $salt = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890';

    // Prepare randomizer
    srand((double)microtime() * 1000000);

    // Create the token
    for($i=0; $i< $sections; $i++)
    {
        for($n=0; $n<$sectionlength; $n++)
        {
            $token.=substr($salt, rand() % strlen($salt), 1);
        }

        if($i<($sections-1)){ $token.='-'; }
    }
   
      $len=strlen($token);
 
        if($len<=50)
          return $token;
       else
        return "Project007Bond";
    
}
    
  
?>
Return current item: MembersGear