我正尝试通过cURL将一些数据从服务器(A)发送到服务器(B),然后根据情况将所述数据放入数据库或从中删除。 问题是我想保护它,并确保不是每个人都可以通过访问服务器(B)将他想要的任何东西放入数据库中。 因此,我对其他数据进行了哈希处理:
<?php
$url = "https://serverB/test.php";
$hash = hash('sha512','UPbztBfJEY7FjDjUZ7kd');//Don't mind the sha512 instead of bcrypt,both my servers aren't working with bcrypt.
$fields = array(
'ref' => 'toasty','name' => 'toasta'
'hash'=> $hash
);
$fields_string = http_build_query($fields);
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
curl_exec($ch);
?>
然后,我们在另一台服务器上对其进行验证:
<?php
$hash=(array_key_exists('hash',$_POST))?$_POST['hash']:'';
if($hash==hash('sha512','UPbztBfJEY7FjDjUZ7kd')){
//Insert the data into the database
}
?>
但是它真的安全吗?如果有人能够读完我发送的内容,即使$hash
很好地进行了哈希处理,他也可以只输入哈希密码就可以发送他想要的任何内容,因为验证可以进行。
够了吗?我该如何做得更好?
请随时问我我想念的更多信息,谢谢!