<tfoot id='jNaC7'></tfoot>
    <legend id='jNaC7'><style id='jNaC7'><dir id='jNaC7'><q id='jNaC7'></q></dir></style></legend>

  • <i id='jNaC7'><tr id='jNaC7'><dt id='jNaC7'><q id='jNaC7'><span id='jNaC7'><b id='jNaC7'><form id='jNaC7'><ins id='jNaC7'></ins><ul id='jNaC7'></ul><sub id='jNaC7'></sub></form><legend id='jNaC7'></legend><bdo id='jNaC7'><pre id='jNaC7'><center id='jNaC7'></center></pre></bdo></b><th id='jNaC7'></th></span></q></dt></tr></i><div id='jNaC7'><tfoot id='jNaC7'></tfoot><dl id='jNaC7'><fieldset id='jNaC7'></fieldset></dl></div>
      <bdo id='jNaC7'></bdo><ul id='jNaC7'></ul>

        <small id='jNaC7'></small><noframes id='jNaC7'>

        PHP - 带 GET 查询的加号

        时间:2023-10-12

              <bdo id='banqX'></bdo><ul id='banqX'></ul>
                <tbody id='banqX'></tbody>
                  <tfoot id='banqX'></tfoot>

                  <small id='banqX'></small><noframes id='banqX'>

                  <legend id='banqX'><style id='banqX'><dir id='banqX'><q id='banqX'></q></dir></style></legend>
                  <i id='banqX'><tr id='banqX'><dt id='banqX'><q id='banqX'><span id='banqX'><b id='banqX'><form id='banqX'><ins id='banqX'></ins><ul id='banqX'></ul><sub id='banqX'></sub></form><legend id='banqX'></legend><bdo id='banqX'><pre id='banqX'><center id='banqX'></center></pre></bdo></b><th id='banqX'></th></span></q></dt></tr></i><div id='banqX'><tfoot id='banqX'></tfoot><dl id='banqX'><fieldset id='banqX'></fieldset></dl></div>
                1. 本文介绍了PHP - 带 GET 查询的加号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个 PHP 脚本,它通过以下方法对字符串进行基本加密:

                  I have a PHP script that does basic encryption of a string through the method below:

                  <?php
                  $key = 'secretkey';
                  $string = $_GET['str'];
                  
                  if ($_GET['method'] == "decrypt")
                  {
                      $output = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode($string), MCRYPT_MODE_CBC, md5(md5($key))), "");
                  }
                  
                  if ($_GET['method'] == "encrypt")
                  {
                      $output= base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key), $string, MCRYPT_MODE_CBC, md5(md5($key))));
                  }
                  
                  echo $output;
                  ?>
                  

                  用于加密字符串的 URL 示例如下所示:

                  An example of a URL to encrypt a string would look like this:

                  Encrypt.php?method=encrypt&str=the quick fox

                  Encrypt.php?method=encrypt&str=the quick fox

                  这将作为加密字符串返回:

                  Which would return this as the encrypted string:

                  LCuT/ieVa6cl3/4VtzE+jd9QPT3kvHYYJFqG6tY3P0Q=

                  LCuT/ieVa6cl3/4VtzE+jd9QPT3kvHYYJFqG6tY3P0Q=

                  现在要解密字符串,您只需将方法"查询更改为解密",如下所示:

                  Now to decrypt the string all you have to do is change the "method" query to "decrypt", like so:

                  Encrypt.php?method=decrypt&str=LCuT/ieVa6cl3/4VtzE+jd9QPT3kvHYYJFqG6tY3P0Q=

                  Encrypt.php?method=decrypt&str=LCuT/ieVa6cl3/4VtzE+jd9QPT3kvHYYJFqG6tY3P0Q=

                  唯一的问题是当加密的字符串被解密时,它会返回:

                  The only problem is that when that encrypted string is decrypted it returns this:

                  §rYV}5·nì(X8;b

                  §rYV}5·nì(X8;b

                  我已将问题缩小到加密字符串中的加号.PHP 的 GET 方法似乎将加号转换为空格.我搜索了这个错误,发现它已经被提交这里.我尝试了该页面上列出的不同方法和其他方法,但均未成功.我得到的最接近的是使用这个:

                  I have narrowed down the problem to the plus sign that is in the encrypted string. PHP's GET method seems to translate a plus sign into a blank space. I have searched this bug and found out that it has already been filed here. I have tried different methods listed on that page and others with no success. The closest I got is by using this:

                  $fixedstring = str_replace(" ", "+", $string);
                  

                  然后在加密方法中使用 $fixedstring ,问题是,在解密时,所有空格都转换为加号.有什么想法吗?

                  and then using $fixedstring in the encryption methods, the problem is, upon decryption, all blank spaces are converted to plus signs. Any ideas?

                  我知道使用 POST 会更有意义,但我出于特定原因使用 GET.我会省略细节.

                  推荐答案

                  如果您阅读该错误报告的全部内容,您将看到对 RFC 2396.这表明 + 是保留的.PHP 将未编码的 + 符号转换为空格是正确的.

                  If you'll read the entirety of that bug report you'll see a reference to RFC 2396. Which states that + is reserved. PHP is correct in translating an unencoded + sign to a space.

                  您可以在将密文返回给用户时使用 urlencode().因此,当用户提交密文进行解密时,您可以 urldecode() 它.如果 PHP 也通过 GET 字符串输入,PHP 会自动为您执行此操作.

                  You could use urlencode() the ciphertext when returning it to the user. Thus, when the user submits the ciphertext for decryption, you can urldecode() it. PHP will do this automatically for you if it comes in via the GET string as well.

                  底线: + 必须作为编码值提交给 PHP:%2B

                  Bottom line: The + must be submitted to PHP as the encoded value: %2B

                  这篇关于PHP - 带 GET 查询的加号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何检查 $_GET 是否为空? 下一篇:为什么 file_get_contents 可用于 google.com 而不能用于我的网站?

                  相关文章

                    <bdo id='q5cDh'></bdo><ul id='q5cDh'></ul>
                2. <i id='q5cDh'><tr id='q5cDh'><dt id='q5cDh'><q id='q5cDh'><span id='q5cDh'><b id='q5cDh'><form id='q5cDh'><ins id='q5cDh'></ins><ul id='q5cDh'></ul><sub id='q5cDh'></sub></form><legend id='q5cDh'></legend><bdo id='q5cDh'><pre id='q5cDh'><center id='q5cDh'></center></pre></bdo></b><th id='q5cDh'></th></span></q></dt></tr></i><div id='q5cDh'><tfoot id='q5cDh'></tfoot><dl id='q5cDh'><fieldset id='q5cDh'></fieldset></dl></div>

                3. <legend id='q5cDh'><style id='q5cDh'><dir id='q5cDh'><q id='q5cDh'></q></dir></style></legend>

                  <small id='q5cDh'></small><noframes id='q5cDh'>

                4. <tfoot id='q5cDh'></tfoot>