Need to encrypt an ID in a URL

Needs to be encryped into something like:

Is this easy to do in PHP?


well, yes you could.

it would probably be in your best intrest to explain exaclty what it is your doing, because theres many ways to go about it, and you would want a suitable solution.

I have a URL like this:


I don’t want user’s going up the the address bar and changing the ID and being able to view someone else’s information. Does this help?

This should be really easy. Just use a random string generator to get some random letters, and intersperse them in the numbers by splitting the id into random chunks 1-3 characters in length. Then have PHP page that parses the id just take out all the letters. Lick clamcrusher said, you could do it a lot of different ways.

Ummm, this may be easy to you, but I don’t know how to do that.


If the ID is an id in a database record then you could add another string field. Use the id plus some other info such as current date time, put it into a string e.g.
12345-13-03-2005-xxx and then do a md5 hash onit, The reuslt of the hash could then be stored in the database. This would give you a random and unique id, no one could then guess at the next/previous account id.
Use the php function md5( string ) which returns the md5 hash result.

Ok, I got some help from a friend who gave me the following code to use as an example. However, this doesn’t work either:

$uID = “9625”;
$key = “encryptkey1943”; // this can be any key value you want

$uIDcrypted = crypt_md5($uID, $key);
$uIDuncrypted = decrypt_md5($uIDcrypted, $key);

echo "key encrypted = " . $uIDcrypted . “<br>”;
echo "key uncrypted = " . $uIDuncrypted . “<br>”;

//output will show:
//key encrypted = ñkMü
//key uncrypted = 9625

I get the following error when I try to view this page:

Fatal error: Call to undefined function: crypt_md5() in /home/busboy/public_html/testimonials/AAAdemo.php on line 11

Any help would be appreciated.

crypt_md5 is not a valid php function…use a simple md5($variable)
and, u cant decypt md5…it is possible, but not practical nor simple.
simple compare an md5($variable) to another md5($anothervariable) to see if they match.

Here is my problem. I want to use this in my URL, like this:

So when a user clicks on that URL, the website will know that AdFefJELweK is really equal to a three digit user ID. So how could I compare two md5($variables)?


do something like this…

Example (not real turn outs):
$id = 123;
$encryptedid = md5($id); //which results in AdFefJELweK for example

pass $encryptedid through the URL…
<? //in php
print “<a href=\“updateEmail.php?uID=$encryptedid\”>Update Users Email</a>”;

then, when you go to updateEmail.php…u $_GET the uID and then compare it to your DB with another md5…as such:

$id = $_GET[‘uID’]; //which will be equal to the md5 of $id…in this case AdFefJELweK

$query = “SELECT * FROM table WHERE md5(UserID) = ‘$id’”;

that should work.

That is because md5 is a hash and not a type of encryption.