Michdd Posted April 25, 2009 Share Posted April 25, 2009 This seems really stupid, but it must be some kind of scope problem.. I'm trying to create something that will allow you to enter an image url into the request variable, then it will redirect you with an encrypted version of that image url in the url then put the water mark on it. So the original URL of the non-watermarked image cannot be traced. eg. You enter: image.php?url=http://something.com/image.png then it redirects you do: image.php?encurl=KSc8NA0YHURXHBBHUFBEJgQwRSkfCERITk1vIwoN where 'KSc8NA0YHURXHBBHUFBEJgQwRSkfCERITk1vIwoN' is the encrypted URL of 'http://something.com/image.png' My encryption and decryption functions work fine. The only problem I'm having is when I use do_decrypt() within the if(isset($_REQUEST['encurl'])) scope it returns nothing.. <?php $key = "ASHD77278qu389*A*S*D0a)))(ASdjuio!$^$RHF"; function xor_crypt($input, $key) { $input_l = strlen($input); $key_l = strlen($key); for ($i=0;$i<$input_l;$i++) { $pos = $i % $key_l; $input[$i] = chr(ord($input[$i]) ^ ord($key[$pos])); } return $input; } function do_encrypt($input, $key) { $input = xor_crypt($input, $key); $input = base64_encode($input); return $input; } function do_decrypt($input, $key) { $input = base64_decode($input); $input = xor_crypt($input, $key); return $input; } if(isset($_REQUEST['url'])) { $encurl = do_encrypt($_REQUEST['url'], $key); $encurl = "http://site.com/image.php?encurl=" . $encurl; echo "<meta http-equiv=\"refresh\" content=\"0;url=$encurl\">"; } if(isset($_REQUEST['encurl'])) { $backurl = do_decrypt($_REQUEST['encurl'], $key); echo $backurl; //Output nothing (?) } Quote Link to comment https://forums.phpfreaks.com/topic/155639-solved-scopes/ Share on other sites More sharing options...
premiso Posted April 25, 2009 Share Posted April 25, 2009 I honestly cannot spot anything wrong, other than can there be a url and encurl request at the same time? If so it is fine, if it is either or, why not use if/elseif ??? Try this for some debugging: function do_decrypt($input, $key) { echo "Start Do Decrypt Debug:<br />Key Passed: {$key}<br />Input Passed: {$input}<br /><br />"; $input = base64_decode($input); echo "Input after base64 decode: {$input}<br /><br />"; $input = xor_crypt($input, $key); echo "Input after base64 and xor_crypt: {$input}"; return $input; } And see what is returned and where it is failing. Do the same for the xoc_crypt if after the base64 it returns fine. Quote Link to comment https://forums.phpfreaks.com/topic/155639-solved-scopes/#findComment-819175 Share on other sites More sharing options...
Michdd Posted April 25, 2009 Author Share Posted April 25, 2009 Key Passed: ASHD77278qu389*A*S*D0a)))(ASdjuio!$^ Input Passed: KSc8NA0YHV4OQE0dSFFFNUUxXydbBF0HSkcsfAUGFxwCUgsqNWF dRh0WlJUAhBSZ2lDOU8/UGtkBFpdB1gvNA== Input after base64 decode: Input after base64 and xor_crypt: I've used these same functions in something else, and they work fine. It seems like it can only be a scope problem. The do_decrypt returns fine if I call it out of the scopes. Quote Link to comment https://forums.phpfreaks.com/topic/155639-solved-scopes/#findComment-819178 Share on other sites More sharing options...
premiso Posted April 25, 2009 Share Posted April 25, 2009 <?php $key = "ASHD77278qu389*A*S*D0a)))(ASdjuio!\$^\$RHF"; // escpaped the $ function xor_crypt($input, $key) { $input_l = strlen($input); $key_l = strlen($key); for ($i=0;$i<$input_l;$i++) { $pos = $i % $key_l; $input[$i] = chr(ord($input[$i]) ^ ord($key[$pos])); } return $input; } function do_encrypt($input, $key) { $input = trim($input); $input = xor_crypt($input, $key); $input = base64_encode($input); return $input; } function do_decrypt($input, $key) { $input = trim($input); $input = base64_decode($input); $input = xor_crypt($input, $key); return $input; } if(isset($_REQUEST['url'])) { $encurl = do_encrypt($_REQUEST['url'], $key); $encurl = "http://misc.dev/test.php?encurl=" . $encurl; echo "<meta http-equiv=\"refresh\" content=\"0;url=$encurl\">"; } if(isset($_REQUEST['encurl'])) { $backurl = do_decrypt($_REQUEST['encurl'], $key); echo $backurl; //Output nothing (?) } ?> I just ran that on my box and received the URL put in there...so it works as far as I know. The only thing I changed, was the trim (which it worked without but decided it was a good idea) and I escaped the two $ in the $key code, as that might have been causing an issue. Edit: Here is the output after I ran that on my box: Input is (decrypt func): KSc8NA0YHUBPBltHUFxfM0YnQiVECF5IR1w1PAEEFhsWUVBwRz0laSg9LCFPGUJfSE4cVwUM Input is after bse64 (decrypt func): )'<4 @O[GP\_3F'B%D^HG\5<QPpG=%i(=,!OB_HNW Output Was: http://www.theurlthatiwanttoencrypt.com/index.php?id=5 (Note I left the debug stuff out in the version posted above). EDIT EDIT: The only issue I saw, is that I actually had an id=5&th=6 for the url and it chopped off everything after the & sign for some reason. Something to look into. Quote Link to comment https://forums.phpfreaks.com/topic/155639-solved-scopes/#findComment-819183 Share on other sites More sharing options...
Michdd Posted April 25, 2009 Author Share Posted April 25, 2009 In the encryptor/decryptor that I use the same functions I did a test and the only difference was that " " was "+" so I changed that using str_replace, then it still output nothing for certain urls (no, they didn't contain &) so I did a test by copy and pasting the REQUEST variable from the URL and hardcoding that into the do_decrypt, and it outputted correctly.. so I'm really confused. Quote Link to comment https://forums.phpfreaks.com/topic/155639-solved-scopes/#findComment-819192 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.