Showing posts with label php encryption. Show all posts
Showing posts with label php encryption. Show all posts

09 March 2011

How to encrypt decrypt url or code in php

When developing web applications sometimes we encounter situations where we need to encrypt/decrypt url or some code or some information. For such situations I wrote a simple php script using the default php functions:
  • base64_encode()
  • base64_decode()
Now the use of these functions is quite simple. For example if you want to pass some critical information like password in the url like:
http://www.example.com/test.php?password=skills2earn
Then you can encode it using the following code:
http://www.example.com/test.php?password=<?php echo base64_encode('skills2earn'); ?>
The output of the above code will be:

http://www.example.com/test.php?password=c2tpbGxzMmVhcm4=

Now when you want to decode/decrypt it you can do it using the following code:
<?php
echo base64_decode('c2tpbGxzMmVhcm4=');
?>
The output of the above code will be:
skills2earn

Well guyz that was a very simple php encryption and decryption technique, if you have any queries or suggestions, please feel free to comment.