English 中文(简体)
第64条:* 残疾,现在做些什么?
原标题:base64_* functions disabled, what to do now?

我在试图利用第64条(代号)职能时正在发出警告。

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

Looks like my host has disabled base64_* functions.

我没有什么问题。

  1. I think base64_* functions can be enabled by default in php, correct?
  2. Is there any security reason why base64_* functions are not enabled? Any security breach?
  3. Alternative to base64_* functions, which are available by default?
  4. Where can I find custom class/functions for base64_* implementation, so that I can have them in my PHP file, and use them if PHP s base64_* functions are not available?

帮助表示感谢。

问题回答

我为所有基64的目的都负有书面替代职能。

参看:

function base64_decode($input) {
    $keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
    $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 =  ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/= ;
    $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);
}

But don t forget the charCodeAt and the charAt function. They are both necessary for base64_encode. The two functions base64_encode and base64_decode both are working like the inbuilt PHP functions. But only use them, if the inbuilt ones are not availible because they re not as fast as the inbuilt ones.

希望!

只是为了评论Jankal的回答而注册的,但可以没有声誉。

最后一行功能基础64 - 扬卡尔的答复中的编码

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

单位:0美元、1美元或2美元。 据我所知,按逻辑计算(r code 3)的表述价值为3美元,其他2起案件的美元=0美元和美元,但实际上(PHP 5.6/7.0)这一表述的价值总是等于1美元,因此,我们的BASE64-encoded string总以2 = 符号结束,这无疑是错误的。

我的解决办法:

return ($r ? substr($enc, 0, ($r - 3)) . substr( === , $r) : $enc);
function myencode($input)
    {
    $CODES = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

    // 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 .= "";
     }
    }

    // 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 += "
";

// 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 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

// 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));
    }

这个问题令人不安。

请修改 主办或要求它们消除这一安全问题





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签