【问题标题】:php doesn't receive encoded $_GET valuesphp 不接收编码的 $_GET 值
【发布时间】:2013-05-06 21:49:42
【问题描述】:

我有一个用公钥加密然后编码的字符串,大概是 200 个字符。

SENDER:
$pubkey = file_get_contents('http://localhost/test/key.pub');
openssl_public_encrypt('hello world', $encrypted, $pubkey);
$first = $encrypted;
$url = 'http://localhost/demo_project/bank/?secure='.urlencode($first);
echo file_get_contents($url);

RECIEVER:
var_dump($_GET);

输出:

array(1) { ["secure"]=> string(0) "" }

安全是secure=Qq%B8%143%F5%D1%15%C4%18%95g%D6%D0%2F%2CH%25%F8%A8%17%EF%2Bl%80%3Bc%9E%F2%9A%FB%CF3%EDj%B7%26%0F%A0%5E%1DM%AB%07%1Db%0F%C3%9E%A1%FF%82%7D%E50%15Vc%08t%0F%07%0Ag

最奇怪的是,如果 secure=Qq%B ,一切正常,但如果 secure=Qq%B8 ,我们就有问题了。

我也尝试过使用 curl 像 here,但它也没有任何好处。有人会指出我的错误并提出解决方案吗?

【问题讨论】:

    标签: php curl get openssl urlencode


    【解决方案1】:

    base64 编码旨在使二进制数据能够通过 非 8 位干净的传输层

    您必须对 openssl_public_encrypt() 的二进制输出数据进行编码。

    发件人:

    $pubkey = file_get_contents('http://localhost/test/key.pub');
    openssl_public_encrypt('hello world', $encrypted, $pubkey);
    $first = base64_encode($encrypted);
    $url = 'http://localhost/demo_project/bank/?secure='.urlencode($first);
    echo file_get_contents($url);
    

    接收者:

    var_dump($_GET);
    $secure = base64_decode($_GET['secure']);
    

    我会使用POST

    $url = 'http://localhost/demo_project/bank/';
    $postdata = array("secure" => $first);
    
    $ch = curl_init();
    
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postdata) );
    echo $response = curl_exec($ch);
    
    curl_close($ch);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-08
      • 2015-12-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-11
      • 2020-04-14
      • 1970-01-01
      相关资源
      最近更新 更多