Using base64 encoded string url

Possible duplicate:
Passing base64 encoded strings to URL

I am working on creating a URL that will be sent to the user. The user then clicks on the URL, and that URL tells me who the user is.

So, all the data that I added to this link using base64 encode. However, when the user clicks on the link, he is redirected to page 404, because there is a β€œ/” in the encoded URL, and the zend framework router does not find any routes for him.

Anyway, can I suppress the "/"? I tried htmlentities , but that didn't work.

+4
source share
2 answers

I highly recommend Create a secure encrypted string by Joe Riggs .

The attached code is procedural, but very simple to convert to OO. I used it to do what you do, in which some information (usually a hash of the email and user ID) is encrypted / encrypted so that the user clicks to activate their account.

The functions you want to view are url_base64_decode and url_base64_encode , in which certain characters are rewritten to be URL safe (for example, removing / and replacing it with ~ ).

[edit]

Here is the code of my class based on the code above: http://codepad.org/lzevA4k1

Using:

 $cryptUtil = new RPK_Crypt(); $string = 'Unencrypted string'; $eString = $cryptUtil->encrypt($string); $dString = $cryptUtil->decrypt($eString); var_dump($dString == $string); //true 
+3
source

I think you need the URL encoding for the characters + , / and = . Try using urlencode() for your encoded Base64 parameter.

PS: By the way, these will be changes: + => %2B , / => %2F and = => %25

-1
source

Source: https://habr.com/ru/post/1441291/


All Articles