I want to encrypt each id at url and from url I want to get back the real value in my script. for security reason. but which functions can encrypt and encrypted string can be turned to a real value with another function ?? Thanks
base64_encode and base64_decode are one example. But the value is not really encrypted since users can decrypt it with base64_decode, for that you'll have to make your own function.
thanks. may be I should play with str_replace function.. 0 will be replaced with e14df3wef 1 will be replaced with 45tdn034f 2 will be replaced with 4hsddnre4 ..........
You mean instead of using encryption? If so, what you're doing can quite easily be reverse engineered. That's not encryption at all. As kblessinggr has said, you'll need to use mcrypt if you want any kind of security... $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); $key = "This is a very secret key"; $text = "Meet me at 11 o'clock behind the monument."; $encrypted = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $text, MCRYPT_MODE_ECB, $iv); $decrypted = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $encrypted, MCRYPT_MODE_ECB, $iv); PHP: Anyway.. you said each ID at the end of the URL, so encrypting like this may be overkill. Why are you doing this? Just so people couldn't guess the URLs like show/1, show/2 etc? Then yes, you could just use base64 functions to do that, or you could add a column to your table that you fill with a unique string for each row that you then use as the identifier.
thanks. there is no need of hard security. simple hit counter service for members for their sites. base64 is enough for my purpose. every member is provided an url with id with html code. if they easily change it, so other members hit counters will not get real report.
You're looking for a simple cypher. Rot13 or ascii shift... or something like that. I wrote one in the past that was a pretty tricky text based cypher. I'm sure there are others out there. Check out this link to PHP rot13 which posts a ascii shift function as well. http://us2.php.net/manual/en/function.str-rot13.php Cheers, Jeff