PHP URL encoding/decoding
P粉512363233
P粉512363233 2023-08-14 13:16:12
0
2
642
<p>I used the accepted solution in this question to encrypt the id, for example in <strong>/index.php?id=3</strong>. The problem is that I cannot send the encrypted value as a url like <strong>/index.php?id=dsf13f3343f23/23=</strong>. Because sometimes there are strange characters in the URL, for example, pay attention to the <code>=</code> symbol</p> at the end
P粉512363233
P粉512363233

reply all(2)
P粉214176639

Use PHP's urlencode() 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 characters in the value passed in the URL should be escaped using urlencode().

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