I used the solution accepted for this question for encrypting by id for example in /index.php?id=3 . The problem is I cannot send the encrypted value as an url, example /index.php?id=dsf13f3343f23/23=. Because sometimes it will have weird characters in the url e.g. notice the =
sign in the end
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
The weird characters in the values passed in the URL should be escaped, using
urlencode(
).For example, the following portion of code :
would give you :
Which works fine, as an URL parameter.
And if you want to build aquery string with several parameters, take a look at the
http_build_query()
function.For example :
will give you :
This function deals with escaping and concatenating the parameters itself ;-)
There is no use in encrypting parameters.
Send it as is:
nothing wrong with it.
Use PHP's
urlencode()
function to encode the value before you put it into a URL.This function converts "weird" characters, such as
=
, into a format safe to put into a URL. You can use it like this:If you use Base64 to encode the binary value for the URL, there is also a variant with URL and filename safe alphabet.
You can use the
strtr
function to translate one from alphabet to the other:So you can use these functions to encode and decode base64url:
See also my answer on What is a good way to produce an short alphanumeric string from a long md5 hash?