Answer the question
In order to leave comments, you need to log in
Attention connoisseurs - md5 lines - different values - why?
Hello. The problem is the following.
Language - php.
I send a POST request to the server. The request parameters are as follows - appdata - {"id":1,"hash":"a08f4db74b7ca13f52b098a3bdc65dd9"} , params - {"asd":123} (generated json).
in the script I process it like this:
if (isset($_POST['appdata'])) //appdata - id,hash of app
{
unset($appdata);
$appdata = json_decode($_POST['appdata'], true);
if (empty($appdata))
{
throw new Exception('$appdata in POST is bad - '.$_POST['appdata'].' from ip - '.$_SERVER["REMOTE_ADDR"], -15);
}
unset($soul);
$soul = _CheckAPP($appdata['id'],$appdata['hash'],$_POST['params']);
function _CheckAPP($id,$hash,$params)
{
if (empty($id) || empty($hash) || empty($params))
{
throw new Exception('$appdata in POST is bad - '.$_POST['appdata'].' from ip - '.$_SERVER["REMOTE_ADDR"], -15);
}
$APP_list=array(
1 => array(
'id' => '1',
'secret' => '882fa0dd30eeca544871f31bc41d244b',
'soul' => 'asd12wez128&712u4h8-0)611297cg*&'
)
);
if (!isset($APP_list[$id]))
{
throw new Exception('This APP Not Registered - '.$id, -11);
}
else
{
$reg_secret=$APP_list[$id]['secret'];
$conc_string=$id.$params.$reg_secret;
if (md5($conc_string)!==$hash)
{
throw new Exception('APP Registered - '.$id.' hash is wrong - '.md5($conc_string), -12);
}
else
{
return $APP_list[$id]['soul'];
}
}
}
Answer the question
In order to leave comments, you need to log in
The problem is most likely in the encodings. To begin with, check the encodings of the files that process your code, utf-8 win-1251 is not critical, the main thing is that there is one thing.
Next, check if you have set the page encoding in the meta tag. Again, one must be the same as the encoding of your files.
If this is true, but still there is an error - convert the string forcibly through iconv
function _CheckAPP($id,$hash,$params)
{
if (empty($id) || empty($hash) || empty($params))
{
throw new Exception('$appdata in POST is bad - '.$_POST['appdata'].' from ip - '.$_SERVER["REMOTE_ADDR"], -15);
}
$APP_list=array(
//APP_OFFICIAL_ANDROID
1 => array(
'id' => '1',
'secret' => '882fa0dd30eeca544871f31bc41d244b',
'soul' => 'asd12wez128&712u4h8-0)611297cg*&'
)
);
if (!isset($APP_list[$id]))
{
throw new Exception('This APP Not Registered - '.$id, -11);
}
else
{
$reg_secret=$APP_list[$id]['secret'];
$conc_string=$id.$params.$reg_secret;
if (md5($conc_string)!==$hash)
{
echo md5('1{"asd":23}882fa0dd30eeca544871f31bc41d244b').' ';//тут все ок
throw new Exception('APP Registered - '.$id.' hash is wrong - '.md5($conc_string).' '.$conc_string.' ', -12);
}
else
{
return $APP_list[$id]['soul'];
}
}
}
try
{
_CheckAPP(1,"400c09327ea9bf1fe9d2223c5e32c7a6",'{"asd":23}');
}
catch (Exception $e)
{
echo $e->getMessage();
}
The problem is here:
The event must be hung on a separate button, and not on all at once
https://codepen.io/anon/pen/prppmg?editors=1011
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question