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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.