garethhall Posted January 27, 2011 Share Posted January 27, 2011 Hi Guys I have a $_GET[] variable that is not echoing out correctly. If I look at $GET in the uri then I have upload-swf.php?s=C2YuzOj+FCPieffLIEYdrtPAAQDVeg+yT+P2+N4Echw= But when I echo <?php echo $_GET['s']; //echo decrypt($_GET['s']); ?> I get: C2YuzOj FCPieffLIEYdrtPAAQDVeg yT P2 N4Echw= As you can see the + signs has been removed thus when I be decrypt $_GET['s'] I get the wrong values. Link to comment https://forums.phpfreaks.com/topic/225815-php-echo-variable-error/ Share on other sites More sharing options...
Pikachu2000 Posted January 27, 2011 Share Posted January 27, 2011 Yup, that's what urldecode() does. $url = "upload-swf.php?s=C2YuzOj+FCPieffLIEYdrtPAAQDVeg+yT+P2+N4Echw="; echo urldecode($url); Returns: upload-swf.php?s=C2YuzOj FCPieffLIEYdrtPAAQDVeg yT P2 N4Echw= Link to comment https://forums.phpfreaks.com/topic/225815-php-echo-variable-error/#findComment-1165840 Share on other sites More sharing options...
garethhall Posted January 27, 2011 Author Share Posted January 27, 2011 But I need it to echo C2YuzOj+FCPieffLIEYdrtPAAQDVeg+yT+P2+N4Echw= Link to comment https://forums.phpfreaks.com/topic/225815-php-echo-variable-error/#findComment-1165842 Share on other sites More sharing options...
Pikachu2000 Posted January 27, 2011 Share Posted January 27, 2011 Is the = on the end supposed to be there also? Link to comment https://forums.phpfreaks.com/topic/225815-php-echo-variable-error/#findComment-1165844 Share on other sites More sharing options...
garethhall Posted January 27, 2011 Author Share Posted January 27, 2011 Yes I thought I'd better include my encryption, decryption functions <?php define('CYPHER', 'My secret key'); /*** Encryption ***/ function encrypt($text){ $ivSize = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); $iv = mcrypt_create_iv($ivSize, MCRYPT_RAND); $encrypt = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, CYPHER, $text, MCRYPT_MODE_ECB, $iv); $encode = base64_encode($encrypt); return trim($encode); } /*** Decryption ***/ function decrypt($text) { $ivSize = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); $iv = mcrypt_create_iv($ivSize, MCRYPT_RAND); $decode = base64_decode($text); $decrypt = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, CYPHER, $decode, MCRYPT_MODE_ECB, $iv); return trim($decrypt); } <? Link to comment https://forums.phpfreaks.com/topic/225815-php-echo-variable-error/#findComment-1165847 Share on other sites More sharing options...
Pikachu2000 Posted January 27, 2011 Share Posted January 27, 2011 I really have nearly no experience with encryption, so this is kind of a shot i the dark. I just ran a few tests though, and from what I could see after sending several different strings through your encrypt() function, the only character it produced that would create a problem is the space. I can't guarantee an airtight solution, but I was able to simply use str_replace to change the spaces back to pluses. Hopefully someone who knows the functions and their behaviors better than I will come along say whether that's a feasible long term solution or not. Link to comment https://forums.phpfreaks.com/topic/225815-php-echo-variable-error/#findComment-1165855 Share on other sites More sharing options...
garethhall Posted January 27, 2011 Author Share Posted January 27, 2011 I still have not been able to come up with a solution. Is there anyone else that can help? Link to comment https://forums.phpfreaks.com/topic/225815-php-echo-variable-error/#findComment-1166133 Share on other sites More sharing options...
BlueSkyIS Posted January 27, 2011 Share Posted January 27, 2011 I get: C2YuzOj FCPieffLIEYdrtPAAQDVeg yT P2 N4Echw= is that what you see in the browser window? or what you see when you View Source? or both? Link to comment https://forums.phpfreaks.com/topic/225815-php-echo-variable-error/#findComment-1166177 Share on other sites More sharing options...
garethhall Posted January 27, 2011 Author Share Posted January 27, 2011 Viewing the source gives C2YuzOj FCPieffLIEYdrtPAAQDVeg yT P2 N4Echw= Link to comment https://forums.phpfreaks.com/topic/225815-php-echo-variable-error/#findComment-1166184 Share on other sites More sharing options...
BlueSkyIS Posted January 27, 2011 Share Posted January 27, 2011 i suspect you'll need to urlencode() that value before using it in a link. something like $key = 'C2YuzOj+FCPieffLIEYdrtPAAQDVeg+yT+P2+N4Echw='; $key_for_url = urlencode($key); $link = "upload-swf.php?s=$key_for_url"; echo "link: $link"; then you may need to urldecode() the GET variable. Link to comment https://forums.phpfreaks.com/topic/225815-php-echo-variable-error/#findComment-1166201 Share on other sites More sharing options...
garethhall Posted January 27, 2011 Author Share Posted January 27, 2011 Thanks so simple All working now. Link to comment https://forums.phpfreaks.com/topic/225815-php-echo-variable-error/#findComment-1166217 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.