Reputation: 1166
I have this url:
https://www.example.com/[email protected]
What is the best way to encrypt the email inside my URL in order to don't let user knows there is an email in the URL, something like:
https://www.example.com/?p=skckqbsBDoia27d
Obviously I will be able to decrypt skckqbsBDoia27d
to get [email protected]
and skckqbsBDoia27d
MUST be unique based on email
.
The solution MUST works with PHP 5.5.
Upvotes: 0
Views: 77
Reputation: 1333
Use base64_encode()
and base64_decode()
accordingly.
[email protected]
will get encoded as c29tZUBlbWFpbC5jb20=
$email = "[email protected]";
$url = "http://www.example.com?param=" . strrev(base64_encode($email));
Then on the receiving side:
echo base64_decode(strrev($_GET['param']));
Upvotes: 1
Reputation: 53553
If you're concerned about disclosing email then the best way would be to just not include the email in any form. Rather, use some other unique identifier that's associated with the user record. If it's not important that it be unguessable, you can just use the database row's pkey field user.id
or whatever. If it needs to be unguessable, I'd create a new field like user.public_id
with a unique constraint and then populate it with a hash or uuid.
Upvotes: 0