-1

I would like to encrypt or encode a string so that it can be placed in a URL query string. I'm currently using the encryption class by ircmaxwell, found here. I'm encrypting with:

$urlstring = base64_encode($crypt->encrypt($string, $pword));

That works flawlessly, but the problem is that this encryption uses chars that cause new lines and other weirdness to appear in the url, meaning that it fails (sometimes) to be clickable. Is there a way to take the result, the encrypted string, and wrap it in some function that would be only be A-Za-z and numbers?

Or maybe there's another, better solution?

Community
  • 1
  • 1
user1149499
  • 573
  • 4
  • 12
  • 30

1 Answers1

3

There are a special PHP functions for this: urlencode(string) and rawurlencode(string)

See http://php.net/manual/de/function.urlencode.php

MrTux
  • 32,350
  • 30
  • 109
  • 146
  • I tried this...thought it looked perfect, did it with both urlencode and realurlencode, but neither worked. My error message isn't useful, just says "There was a problem" but it's when the GET variable that's the string doesn't match the variable stored in the db. So something's still not working. It works fine if I use md_rand() or some other normal string. But when I encrypt it fails. Grrr. Thank you though for this suggestion...I was sure it was exactly what I needed. – user1149499 Aug 25 '14 at 03:00
  • Actually, I might have this same problem: http://stackoverflow.com/questions/1971091/problem-encrypting-encoding-url-variable?rq=1 – user1149499 Aug 25 '14 at 03:02