PHP URL encoding/decoding
P粉512363233
P粉512363233 2023-08-14 13:16:12
0
2
443

I used the accepted solution in this question to encrypt the id, for example in /index.php?id=3. The problem is that I cannot send the encrypted value as a url like /index.php?id=dsf13f3343f23/23=. Because sometimes there are strange characters in the URL, for example, pay attention to the = symbol

at the end
P粉512363233
P粉512363233

reply all (2)
P粉214176639

Use PHP'surlencode()function to encode the value before putting it in the URL.

This function converts "strange" characters, such as=, into a format that is safe to put in the URL. You can use it like this:

Header('Location: /index.php?id=' . urlencode($id))
    P粉346326040

    Strange charactersin the value passed in the URL should be escaped usingurlencode().

    For example, the following code snippet:

    echo urlencode('dsf13f3343f23/23=');
    will give:

    dsf13f3343f23%2F23%3D
    As a URL parameter, this is valid.

    If you want to build a query string with multiple parameters, check out the
    http_build_query()function.

    For example:

    echo http_build_query(array( 'id' => 'dsf13f3343f23/23=', 'a' => 'plop', 'b' => '$^@test', ));
    will give:

    id=dsf13f3343f23%2F23%3D&a=plop&b=%24%5E%40test
    This function will automatically handle escaping and parameter splicing;-)

      Latest Downloads
      More>
      Web Effects
      Website Source Code
      Website Materials
      Front End Template
      About us Disclaimer Sitemap
      php.cn:Public welfare online PHP training,Help PHP learners grow quickly!