2012-04-19 10 views
5

मैं() फ़ंक्शन जब मैं base64_decode इस्तेमाल करने की कोशिश निम्न चेतावनी हो रही हैbase64_ * फ़ंक्शंस अक्षम, अब क्या करना है?

"Warning: base64_decode() has been disabled for security reasons" 

लग रहा है मेरी मेजबान की तरह विकलांग base64_ * कार्य करती है।

मैं कुछ सवाल

  1. है मुझे लगता है कि base64_ * कार्यों php में डिफ़ॉल्ट रूप से सक्षम किया जा सकता है, सही है?
  2. क्या कोई सुरक्षा कारण है कि base64_ * फ़ंक्शन सक्षम नहीं हैं? कोई सुरक्षा उल्लंघन?
  3. आधार 64_ * कार्यों के लिए वैकल्पिक, जो डिफ़ॉल्ट रूप से उपलब्ध हैं?
  4. मुझे बेस 64_ * कार्यान्वयन के लिए कस्टम क्लास/फ़ंक्शंस कहां मिल सकता है, ताकि मैं उन्हें अपनी PHP फ़ाइल में रख सकूं, और PHP का बेस 64_ * फ़ंक्शंस उपलब्ध नहीं होने पर उनका उपयोग कर सकता हूं?

सहायता की सराहना की।

+0

बुरा स्क्रिप्ट के आवंटित base_64 eval कार्यों में इनकोड। यदि आपको वास्तव में इसकी आवश्यकता है, तो मेजबान –

+4

बदलें यदि आपका होस्ट "परावर्तक द्वारा सुरक्षा" में विश्वास करता है ... परिवर्तन HOSTS। –

+0

उनके जासूस सॉफ्टवेयर बेस 64 संगत नहीं है? :) – Hajo

उत्तर

-2

यह समस्या होस्टिंग है।

अपने होस्टिंग बदलें या उन्हें पूछना सभी बेस 64 प्रयोजनों के लिए इस सुरक्षा समस्या

7

मैं लिखा है विकल्प कार्यों को हटाने के लिए करें।

यहाँ देखो:

function base64_decode($input) { 
    $keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz/="; 
    $chr1 = $chr2 = $chr3 = ""; 
    $enc1 = $enc2 = $enc3 = $enc4 = ""; 
    $i = 0; 
    $output = ""; 

    // remove all characters that are not A-Z, a-z, 0-9, +, /, or = 
    $filter = $input; 
    $input = preg_replace("[^A-Za-z0-9\+\/\=]", "", $input); 
    if ($filter != $input) { 
     return false; 
    } 

    do { 
     $enc1 = strpos($keyStr, substr($input, $i++, 1)); 
     $enc2 = strpos($keyStr, substr($input, $i++, 1)); 
     $enc3 = strpos($keyStr, substr($input, $i++, 1)); 
     $enc4 = strpos($keyStr, substr($input, $i++, 1)); 
     $chr1 = ($enc1 << 2) | ($enc2 >> 4); 
     $chr2 = (($enc2 & 15) << 4) | ($enc3 >> 2); 
     $chr3 = (($enc3 & 3) << 6) | $enc4; 
     $output = $output . chr((int) $chr1); 
     if ($enc3 != 64) { 
      $output = $output . chr((int) $chr2); 
     } 
     if ($enc4 != 64) { 
      $output = $output . chr((int) $chr3); 
     } 
     $chr1 = $chr2 = $chr3 = ""; 
     $enc1 = $enc2 = $enc3 = $enc4 = ""; 
    } while ($i < strlen($input)); 
    return urldecode($output); 
} 

function base64_encode($data) { 
    $b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz/='; 
    $o1 = $o2 = $o3 = $h1 = $h2 = $h3 = $h4 = $bits = $i = 0; 
    $ac = 0; 
    $enc = ''; 
    $tmp_arr = array(); 
    if (!$data) { 
     return data; 
    } 
    do { 
    // pack three octets into four hexets 
    $o1 = charCodeAt($data, $i++); 
    $o2 = charCodeAt($data, $i++); 
    $o3 = charCodeAt($data, $i++); 
    $bits = $o1 << 16 | $o2 << 8 | $o3; 
    $h1 = $bits >> 18 & 0x3f; 
    $h2 = $bits >> 12 & 0x3f; 
    $h3 = $bits >> 6 & 0x3f; 
    $h4 = $bits & 0x3f; 
    // use hexets to index into b64, and append result to encoded string 
    $tmp_arr[$ac++] = charAt($b64, $h1).charAt($b64, $h2).charAt($b64, $h3).charAt($b64, $h4); 
    } while ($i < strlen($data)); 
    $enc = implode($tmp_arr, ''); 
    $r = (strlen($data) % 3); 
    return ($r ? substr($enc, 0, ($r - 3)) . substr('===', $r) : $enc); 
} 

function charCodeAt($data, $char) { 
    return ord(substr($data, $char, 1)); 
} 

function charAt($data, $char) { 
    return substr($data, $char, 1); 
} 

लेकिन charCodeAt और charAt समारोह मत भूलना। वे दोनों base64_encode के लिए आवश्यक हैं। दो कार्य base64_encode और base64_decode दोनों अंतर्निहित PHP फ़ंक्शंस की तरह काम कर रहे हैं। लेकिन केवल उनका उपयोग करें, अगर इनबिल्ट वाले लोग उपलब्ध नहीं हैं क्योंकि वे इनबिल्ट वाले जितना तेज़ नहीं हैं।

उम्मीद है कि यह मदद करता है!

+0

मैं तुमसे प्यार करता हूँ! यह वह उत्तर है जिसे आप किसी आपात स्थिति में ढूंढना चाहते हैं जहां कोड = पी –

+1

धन्यवाद @Ivan Shatsky 'वापसी ($ आर? सबस्ट्रेट ($ एनसी, 0, ($ आर -3))। Substr ('== = ', $ r): $ enc); ' – jankal

+0

यदि आपको _base64_decode_ के सटीक व्यवहार की नकल करने की आवश्यकता है, जैसा कि मैंने किया है, तो आपको" FALSE लौटाता है यदि इनपुट में बेस 64 वर्णमाला के बाहर से वर्ण होता है। "(जैसा कि [PHP मैनुअल] (https://secure.php.net/manual/en/function.base64-decode.php#refsect1-function.base64-decode-parameters) कहते हैं)। ऐसा करने के लिए, मैंने $ इनपुट नाम $ फ़िल्टर में बदल दिया (पैरामीटर के मूल मान को संरक्षित किया) और फिर मैंने लाइन जोड़ा: 'अगर ($ फ़िल्टर! = $ इनपुट) झूठी वापसी; '। –

1

सिर्फ जंकल के जवाब पर टिप्पणी करने के लिए पंजीकृत है, लेकिन प्रतिष्ठा के बिना इसे नहीं कर सकता।

jankal के जवाब में समारोह base64_encode कोड की

अंतिम पंक्ति

return ($r ? substr($enc, 0, ($r - 3)) : $enc) . substr('===', ($r || 3)); 

जहां $ आर हो सकता है 0, 1 या 2. मैं समझता हूँ के रूप में, ($ आर || 3) कोड तर्क के आधार पर अभिव्यक्ति मान होना चाहिए है 3 जब $ r = 0, और $ दो अन्य मामलों में, लेकिन अभ्यास में (PHP 5.6/7.0) इस अभिव्यक्ति का मान हमेशा 1 के बराबर होता है, इसलिए हमारी BASE64-एन्कोडेड स्ट्रिंग हमेशा दो '=' प्रतीकों के साथ समाप्त होती है, जो कि है निश्चित रूप से गलत

मेरे समाधान:

return ($r ? substr($enc, 0, ($r - 3)) . substr('===', $r) : $enc); 
+1

बहुत बहुत धन्यवाद! – jankal

+1

क्या संपादन करते समय मुझे अपने उत्तरों में आपके परिवर्तनों का उपयोग करने की अनुमति है? – jankal

+2

मैंने अभी किया ... यदि कोई शिकायत है: कृपया टिप्पणी करें या मुझे एक संदेश भेजें। – jankal

0
function myencode($input) 
    { 
    $CODES = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz/="; 

    // the result/encoded string, the padding string, and the pad count 
    $r = ""; 
    $p= ""; 
    $c = strlen($input) % 3; 

    // add a right zero pad to make this string a multiple of 3 characters 
    if ($c > 0) 
    { 
     for (; $c < 3; $c++) 
    { 
     $p .= "="; 
     $input .= "\0"; 
    } 
    } 

    // increment over the length of the string, three characters at a time 
    for ($c = 0; $c < strlen($input); $c += 3) { 

// we add newlines after every 76 output characters, according to the MIME specs 

     if ($c > 0 && ($c/3 * 4) % 76 == 0) 
     $r += "\r\n"; 

// these three 8-bit (ASCII) characters become one 24-bit number 
$n = (ord($input[$c]) << 16) + (ord($input[$c +1]) << 8) + (ord($input[$c +2])); 


     // this 24-bit number gets separated into four 6-bit numbers 
     $n1 = $n >> 18 & 63; 
     $n2 = $n >> 12 & 63; 
     $n3 = $n >> 6 & 63; 
     $n4 = $n & 63; 

// those four 6-bit numbers are used as indices into the base64 character list 

$r .= "" . $CODES[$n1] . $CODES[$n2] . $CODES[$n3] . $CODES[$n4]; 

    } 
    return substr($r,0,(strlen($r)-strlen($p))) . $p; 
    } 



function mydecode($input) { 

$CODES = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz/="; 

// remove/ignore any characters not in the base64 characters list 
    // or the pad character -- particularly newlines 

    $input= str_replace("[^" . $CODES . "=]","",$input); 

    // replace any incoming padding with a zero pad (the 'A' character is zero) 
    $p = ($input[strlen($input) - 1] == '=' ?($input[strlen($input) - 2] == '=' ? "AA" : "A") : ""); 

    $r = ""; 
    $input = substr($input,0,(strlen($input) - strlen($p))) . $p; 
// increment over the length of this encoded string, four characters at a time 
    for ($c = 0; $c < strlen($input); $c += 4) { 

// each of these four characters represents a 6-bit index in the 
// base64 characters list which, when concatenated, will give the 
// 24-bit number for the original 3 characters 

     $n=(strpos($CODES,$input[$c]) << 18) 
     + (strpos($CODES,$input[$c+1]) << 12) 
     + (strpos($CODES,$input[$c+2]) << 6) 
     + (strpos($CODES,$input[$c+3])); 


// split the 24-bit number into the original three 8-bit (ASCII) characters 
$r .= "" . chr(($n >> 16) & 0xFF) . chr((($n >> 8) & 0xFF)) . chr(($n & 0xFF)); 

    } 
    // remove any zero pad that was added to make this a multiple of 24 bits 
     return substr($r,0, strlen($r)- strlen($p)); 
    } 
संबंधित मुद्दे