Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Robert Walker
Robert Walker
17,146 Points

base64_encode(openssl_random_pseudo_bytes(32)) issues

As the title suggests I am having an issue with base64_encode(openssl_random_pseudo_bytes(32))

A little background for you, I am using the above to provide a password reset code which is emailed to the user and then used as a hidden input on the reset password form.

I have an issue where + symbols are being removed when using GET to print the reset code into the hidden input field.

For example:

9Y8+Wc6MSSPK8krCBszEdGZJx8v3j9qt/i/tbKBB6z8=

becomes:

9Y8 Wc6MSSPK8krCBszEdGZJx8v3j9qt/i/tbKBB6z8=

So just to go over that once more, I use base64 and openssl to create a string (works perfectly), the user is then emailed a link with this code as GET, IE mywebsite.com/?reset=9Y8+Wc6MSSPK8krCBszEdGZJx8v3j9qt/i/tbKBB6z8=, I then use PHP $_GET['reset'] to echo out the reset code into a hidden input field and this is where my issue is, the + symbol has been replaced with a space and I have no idea why or how to fix it.

Robert Walker
Robert Walker
17,146 Points

Just to add I know how to adjust my code to make a work around for this but I need to understand the actual problem and why this happens.