2012-10-20 160 views
-1

我正在使用具有編碼鏈接選項的Flash播放器。我可以使用下面的代碼成功地對它們進行編碼,但是我找不到解碼的方法,並且它們不提供該選項。PHP:從編碼解碼?

鏈接與球員的工作,我的問題開始的時候,我需要對它們進行編輯。而不是我看到編碼版本的正常鏈接。

<?php 
    function uppod_enc_replace($str){ 
      $uppod_tmp_a=Array('G','d','R','0','M','Y','4','v','6','u','t','i','f','c','s','l','B','5','n','2','V','Z','J','m','L','='); 
      $uppod_tmp_b=Array('1','w','Q','o','9','U','a','N','x','D','X','7','z','H','y','3','e','g','T','W','b','8','k','I','p','r'); 
      $uppod_tmp=$str; 
      $uppod_tmp_from=$uppod_tmp_a; 
      $uppod_tmp_to=$uppod_tmp_b; 

      for($i=0;$i<sizeof($uppod_tmp_from);$i++){ 

       $uppod_tmp=uppod_enc_replace_ab($uppod_tmp_from[$i],$uppod_tmp_to[$i],$uppod_tmp); 
      } 
      return $uppod_tmp; 
    } 
    function uppod_enc_replace_ab($a,$b,$tmp){ 
      $tmp=preg_replace('/'.$a.'/','___',$tmp); 
      $tmp=preg_replace('/'.$b.'/',$a,$tmp); 
      $tmp=preg_replace('/___/',$b,$tmp); 
      return $tmp; 
    } 
    function uppod_encode($str,$lkey=''){ 
      $tmp=uppod_enc_replace(base64_encode($str)); 
      if($lkey!=''){ 
        $tmpn=rand(0,strlen($tmp)); 
        $tmp=substr($tmp,0,$tmpn).uppod_enc_replace(base64_encode($lkey)).substr($tmp,$tmpn); 
      } 
      return $tmp; 
    } 
?> 

什麼我試過到目前爲止:

switching places 
        $uppod_tmp_from=$uppod_tmp_a; 
        $uppod_tmp_to=$uppod_tmp_b; 
changing base64_encode to base64_decode 

測試:

stackoverflow.com 
encodes to: 
HlQhUWXNwIbs8I6NwsgjVWor 

changing base64_encode to base64_decode and switching places with $uppod_tmp_from=$uppod_tmp_a; $uppod_tmp_to=$uppod_tmp_b; 
decodes to: 
n!RB▒▒▒▒▒▒#Yj+[ 
+0

只是爲了澄清,這部分是無法解碼?服務器端還是客戶端?服務器端爲 – Leri

+0

。當我編輯鏈接從acp我看到編碼版本。 –

回答

2

後切換字母后面

  • BASE64_DECODE()通過稍微修改uppod_enc_replace功能:

    function uppod_enc_replace($str, $direction = 'encode'){ 
        $uppod_tmp_a=Array('G','d','R','0','M','Y','4','v','6','u','t','i','f','c','s','l','B','5','n','2','V','Z','J','m','L','='); 
        $uppod_tmp_b=Array('1','w','Q','o','9','U','a','N','x','D','X','7','z','H','y','3','e','g','T','W','b','8','k','I','p','r'); 
        $uppod_tmp=$str; 
        if($direction == 'encode'){ 
         $uppod_tmp_from = $uppod_tmp_a; 
         $uppod_tmp_to = $uppod_tmp_b; 
        }else{ 
         $uppod_tmp_to = $uppod_tmp_a; 
         $uppod_tmp_from = $uppod_tmp_b; 
        } 
    
        for($i=0;$i<sizeof($uppod_tmp_from);$i++){ 
         $uppod_tmp=uppod_enc_replace_ab($uppod_tmp_from[$i],$uppod_tmp_to[$i],$uppod_tmp); 
        } 
        return $uppod_tmp; 
    } 
    

    解碼E類功能看起來就像這樣:

    function uppod_decode($str, $lkey = ''){ 
        if($lkey!=''){ 
         $eKey = uppod_enc_replace(base64_decode($lkey)); 
         $str = str_replace($eKey, '', $str); 
        } 
        return base64_decode(uppod_enc_replace($str, 'decode')); 
    } 
    

    測試用例:

    $url = 'http://www.google.com/'; 
    
    $encoded = uppod_encode($url); 
    $decoded = uppod_decode($encoded); 
    
    var_dump($decoded); 
    
    $key = base64_encode('p45sw0rd'); 
    
    $encoded2 = uppod_encode($url, $key); 
    $decoded2 = uppod_decode($encoded2, $key); 
    
    var_dump($decoded2); 
    
    // outputs: 
    // string(22) "http://www.google.com/" 
    // string(22) "http://www.google.com/" 
    
  • +0

    工作!非常感謝! –

    0

    編碼腳本是這樣做的:

    1. BASE64_ENCODE()
    2. SWITC興一些字母

    所以要對其進行解碼,您需要:

    +0

    這就是我所做的,但我得到了胡言亂語 –