File size: 2,776 Bytes
bae6a7c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php 
class MZA_SecureUrl{
   private $valid_url, $parse, $length, $point1, $point2;
     
   function MZA_SecureUrl(){
      $this->obj =& get_instance();
      $this->valid_url = md5('mza secure url');  // you can change the string
      $this->parse  = 'mza secure url';  // you can change the string
      $this->length  = 5;  // you can change the value. Min : 1, Max : 32;
      $this->point1  = 5;  // you can change the value. Min : 1, Max : point1 + length : 32
      $this->point2  = 17;  // you can change the value. Min : 1, Max : point2 + length : 32
   }
  
   function _get_iv(){
      $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
      return mcrypt_create_iv($iv_size, MCRYPT_RAND);
   }
  
   function setSecureUrl_encode($class,$function, $param = array()){ // array $param only singel dimension of array, can't <span class="short_text" id="result_box" lang="en"><span class="hps">multiple</span> <span class="hps">dimensions</span></span>. 
      $parameter = '';             // Send me an email if you have any suggestion. 
      $function = $this->_encodeUrl($function);
      if(!empty($param)){
  foreach($param as $value){
     $parameter .= $value.'/';
         }   
         $parameter = $this->_encodeUrl(substr($parameter,0,-1));
         return $class.'/secure/'.substr($this->valid_url,$this->point1,$this->length).$function.substr($this->valid_url,$this->point2,$this->length).$parameter;
      }else{
  return $class.'/secure/'.substr($this->valid_url,$this->point1,$this->length).$function;
      }
   }
  
   function _encodeUrl($url){
      return str_replace(array('+','/','='),array('-','_',' '),base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($this->parse), $url, MCRYPT_MODE_ECB, $this->_get_iv())));
   }
  
   function _decodeUrl($url){
      return mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($this->parse), base64_decode($url), MCRYPT_MODE_ECB, $this->_get_iv());
   }
  
   function setSecureUrl_decode($url){
      $url = str_replace(array('-','_',' '),array('+','/','='),urldecode($url));
      if($this->_isValid_url($url)){
  $parameter = '';
  $data = explode(substr($this->valid_url,$this->point2,$this->length),substr($url,$this->length));
  $url = $this->_decodeUrl($data[0]);
  if(!empty($data[1])){
     $parameter = trim($this->_decodeUrl($data[1]));
     $parameter = explode('/', $parameter);  
     return array('function' => trim($url), 'params' => $parameter);
  }else{
     return array('function' => trim($url), 'params' => null);
  }
      }else{
  return false;
      }
   }
  
   function _isValid_url($url){
      if(strcmp(substr($url,0,$this->length),substr($this->valid_url,$this->point1,$this->length)) == 0){
         return true;
      }else{
  return false;
      }
   }
}
?>