Skip to content
Advertisement

How to encrypt the $_GET data in php?

As in php we use $_GET to pass variables in the url , i want to pass variables which include the id of the user which i want to be anonymous, so can something be done which can encrypt the variable before passing it and the the variable once taken on the page can be decrypted to get the original variable value.

for eg:

Before passing variable $id=10;

Passed in the url as $id=dasfgjg;

when taken from the url and decrypted $id=10;

How can this be achieved?

Advertisement

Answer

You can use an RC4 cipher if you intend to encrypt/decrypt only on the server-side

http://www.phpkode.com/source/s/rc4-cipher-0-1/rc4-cipher-0-1/RC4.php

$my_secret_key = '3klmsd94mms.saeo44o!!3le';

if( isset($_GET['p']) ) {
  $id = RC4::decrypt($my_secret_key, $_GET['p']);
  // ....
}
else {
  echo '<a href="/?p='.RC4::encrypt($my_secret_key, 12).'">Go to the page</a>';
}
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement