1

This may be easy but I cannot seem to get it.. Heres all of the code:

function logRequest($currIP){

include("include/opendb.php");

$gets = $_SERVER['QUERY_STRING'];
$posts = http_build_query($_POST);

$ref = $_SERVER['HTTP_REFERER'];
$agent = $_SERVER['HTTP_USER_AGENT'];
$date = date('Y-m-d H:i:s');
$rlookup = $_SERVER['REMOTE_HOST'];
$requestType = $_SERVER['REQUEST_METHOD'];
$languageset = $_SERVER['HTTP_ACCEPT_LANGUAGE'];

$key = "GSICHECKPOINT1";
$combinedVars = array("combinded" ,$date, $currIP, $ref, $agent, $rlookup, $requestType, $languageset, $gets, $posts);
$array[0] = $encryptID = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key), $combinedVars, MCRYPT_MODE_CBC, md5(md5($key))));
$array[1] = $decryptID = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode($encryptID), MCRYPT_MODE_CBC, md5(md5($key))), "\0");   


$query = "INSERT INTO loadAttempts (date, IP, ref, useragent, dnslookup, requestType, language, gets, posts) VALUES ('$date', '$currIP', '$ref', '$agent', '$rlookup','$requestType', '$languageset', '$gets', '$posts')";
$result = mysql_query($query);

return $array;


}

I want to return both the $encryptID and $decryptID from the function, so I put them into an array. (was this wrong?)

Then I am trying to submit these returned values into another function using this code:

        if(in_array($_SERVER['REMOTE_ADDR'], $blockIP)){
            // Log attempt to get here.
            list($encryptID, $decryptID) = logRequest($currIP);
            // Send user to blockpage.
            blockPage($encryptID, $decryptID);
        }else{ 
                       blah blah blah

My question is, when I am pulling these returned values, the blockPage displayed "Array" for the $decryptID and I don't know where I messed up pulling these values out of the function. How do I show each item inside of the $decrpytID array when its already out of the creator function?

Thank you!

1
  • Can you do a var_dump or printr on what logRequest($currIP) returns? it would probably shed some light on whats going wrong. Commented Dec 26, 2011 at 20:38

1 Answer 1

0

The problem is that you have passed an array $combinedVars to the third ($data) argument of mcrypt_encrypt(), when the manual calls for a string to be passed. This will result in the array being converted to the string Array, which is why this is what you see decrypted.

From the manual:

Arrays are always converted to the string "Array"

You need to convert the string to an array in a more intelligent way, that shows the values - so you may want to serialize() it, or json_encode() it, or possibly just print_r() it, passing TRUE to the second argument to return the string. Which you will want to do depends on what you want to do with the data.

The only other thing that is obviously wrong is that combinded should probably say combined.

I must say I don't quite understand the purpose of this function - why would you have a function that returns the same data in encrypted and decrypted formats, and even if this is of some use, what is the point of doing the extra work to decrypt the data that you just encrypted and return the result of that, when you could just return the data you encrypted...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.