Jump to content

Php echo variable error


garethhall

Recommended Posts

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

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=

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);
}

<?

 

 

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.