Link to home
Start Free TrialLog in
Avatar of Bruce Gust
Bruce GustFlag for United States of America

asked on

What am I doing wrong with these hash marks?

When I use this:

$voter_email="bruce@brucegust.com";
$key = "qP9wXOx+Dk0iVCmUQDEkLCf5";
$str= $voter_email.''.$key;
$digest = sha1($str, true);
$the_digest =  base64_encode($digest);
$road_digest=htmlentities($the_digest);

The subsequent string is Cd7cT2coaEI1R++ddSx/XX4sBHs=

Problem is, when I embed that into a URL, and grab it using a "GET," I lose the "++".

What am I doing wrong?

In other words, the URL will look like http://www.myserver.php?chk=Cd7cT2coaEI1R++ddSx/XX4sBHs=


But when I go to grab it using a $_GET['chk'], it gives me Cd7cT2coaEI1RddSx/XX4sBHs=


What am I doing wrong?
SOLUTION
Avatar of Kiran Sonawane
Kiran Sonawane
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Bruce Gust

ASKER

I'm trying to figure it out, but I'm coming up short. How do I use what it is you're suggesting?

I just tried the urlencode and wound up with a big mess.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
base64_encode() won't be adequate because it includes the '+' and '/' characters which must be URLencoded.  http://en.wikipedia.org/wiki/Base64  And 'htmlentities()' could possibly put '&' in the query string which are supposed to designate the start of a name/value pair so you don't really want that.

I was wondering why you don't just take the hex output of sha() because it is perfectly safe consisting of 0-9 and a-f and doesn't need anymore encoding.
I do not find any problem with using base64_encode() to create a URL string.  Please see:
http://www.laprbass.com/RAY_encrypt_decrypt_GET.php?clearstring=&cryptstring=XEnjL5CT6s%2BYgJgtiFsHqPg6wFS6JQ9gQT94nGoqfic%3D

This is just the same encrypt/decrypt script posted above, but with the POST method changed to the GET method so that the data is passed in the URL.  I tried a few different strings and did not encounter any character encoding issues.  The data seems to survive the round trip unscathed.
But the string is URLencoded, Ray, that was the point.
Dave: Yes, I think the browser or the server or something else handled the encoding for me.  It's not part of my script; that's 100% of the instructions in the earlier code snippet.
Normally, an HTML form submission in the browser will do that for you.  But that means it can still be part of the problem if the author is constructing his own query string for something like curl() or another PHP function that accesses a file by HTTP.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You're right, htmlentities()  could cause problems if it added a '&' to the query string because that is a separator for name/value pairs.
Thanks, guys!