Good time!

I create a POST request and send it to another URL . The request contains the generated md5 hash. The problem is that having the same values, I get different hashes. Why it happens?

Request:

 $merchant_password = "password"; $merchant_name = "Name merchant"; $amount = "100"; $date = "2017-06-09 11:20:16"; $id_transfer = "f191a923-6311-47c8-bc38-04851355ae68"; $fee = "30"; $hash_string2= $amount.':' .$merchant_password.':' .$date.':' .$id_transfer; $hash2=strtoupper(md5($hash_string2)); // Send POST request $url = "http://example.com/post.php"; $post_data = array ( "amount" => $amount, "fee" => $fee, "method" => "ADV Cash", "merchant_name" => $merchant_name, "status" => "Confirmed", "date" => $date, "id_method_transaction" => $id_transfer, "ballance" => "123", "hash" => $hash2 ); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // указываем, что у нас POST запрос curl_setopt($ch, CURLOPT_POST, 1); // добавляем переменные curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); $output = curl_exec($ch); curl_close($ch); echo $output; }else{ } 

Request handler:

 <?php // строка, которую будем записывать $merchant_password = "password"; $amount = $_POST['amount']; $fee = $_POST['fee']; $method = $_POST['method']; $status = $_POST['status']; $date = $_POST['date']; $id_method_transaction = $_POST['id_method_transaction']; $ballance = $_POST['ballance']; $merchant_name = $_POST['merchant_name']; $id_transfer = $_POST['id_transfer']; $hash = $_POST['hash']; $hash_string= $amount.':' .$merchant_password.':' .$date.':' .$id_transfer; $user_hash=strtoupper(md5($hash_string)); // открываем файл, если файл не существует, //делается попытка создать его $fp = fopen("file.txt", "w"); // записываем в файл текст fwrite($fp, $amount . ' ' . $fee . ' ' . $method . ' ' . $status . ' '. $date . ' '. $id_method_transaction . ' '. $ballance . ' '. $merchant_name . ' ' .$id_transfer . ' ' . $hash . ' // user hash - ' . $user_hash); // закрываем fclose($fp); ?> 

The result of the query:

100 30 ADV Cash Confirmed 2017-06-10 11:20:16

Grateful for any help or direction!

  • Which of the hashes is different? Which one do you send or record? - tutankhamun
  • one
    make sure the strings from which the hash is considered identical. then make sure that the encoding of both php files matches. - teran
  • one
    @teran php file encoding here? Immediately it seems only Latin. I don’t think that someone will become UCS2, for example, use - tutankhamun
  • one
    @tutankhamun there is a concatenation with a colon, in utf-8 and 16 or 1251 there will be different meanings. - teran
  • one
    @teran Well, there really will be a difference in UTF-16. But something seems to me that in UTF-16 nobody holds the source code. Maybe I'm wrong - tutankhamun

1 answer 1

$ id_transfer = $ _POST ['id_transfer'];

Please find the data to be sent id_transfer. He's not there.

With NULL instead of id_transfer, just the observed hash is obtained.

Therefore, you do not read even the most banal that you can think of - the messages of your best friend, a programming language. If you don’t read the interpreter’s warnings, then why be surprised?