php 给 request 添加项,PHP将签名添加到POST请求(PHP Add Signature to POST Request)

PHP将签名添加到POST请求(PHP Add Signature to POST Request)

我正在尝试用PHP发出POST请求。 我试图提交用户名和生成的哈希。 以下是我目前的代码:

if( isset($_POST["name"]) && crypt($_POST["name"],'saltgoeshere') == $_POST["hash"] )

{

echo "Name is ". $_POST['name']. "
";

exit();

}

else if( isset($_POST["name"]) && crypt($_POST["name"],'saltgoeshere') != $_POST["hash"] ) {echo "Invalid/Tampered Request?"; exit();}

?>

Name:

Password: " />

用户提交他们的名称,脚本根据他们的输入创建一个哈希,并创建一个包含名称和哈希的POST请求。 然后,该脚本查看post请求并检查提交的哈希是否与实际哈希匹配。

我目前的问题是根据用户输入生成散列,因为PHP是预处理器。

制作AJAX请求会解决这个问题吗?

编辑:我正在尝试确保用户在提交数据时没有篡改数据。

I am trying to make a POST request with PHP. I am trying to submit a users name along with a generated hash. The following is the code I currently have:

if( isset($_POST["name"]) && crypt($_POST["name"],'saltgoeshere') == $_POST["hash"] )

{

echo "Name is ". $_POST['name']. "
";

exit();

}

else if( isset($_POST["name"]) && crypt($_POST["name"],'saltgoeshere') != $_POST["hash"] ) {echo "Invalid/Tampered Request?"; exit();}

?>

Name:

Password: " />

The users submits their name and the script creates a hash based on their input and creates a POST request with both the name and hash. The script then looks at the post request and checks if the hash that was submitted, matches the actual hash.

The problem that I currently have is generating the hash based on the users input because PHP is a Preprocessor.

Would making an AJAX request fix this issue?

Edit: I am trying to make sure the user has not tamped with the data when it has been submitted.

原文:https://stackoverflow.com/questions/28649188

更新时间:2020-01-20 17:01

最满意答案

我试图确保用户在提交数据时没有篡改数据。

非常生硬:这是一个非常愚蠢的原因。 用户正在将数据输入表单并将其提交给您。 他们已经在“篡改”数据。 想要以任何方式签署此数据没有任何意义。 即使PHP作为“预处理器”的“问题”不存在,它将如何工作? PHP会接受用户输入的数据,签名,然后将其提交给自己并检查签名? 您可以跳过整个过程,只需获取用户的输入,即可获得相同的结果。

你可以在Javascript中进行签名,但这同样是无稽之谈。 您正在提供可以为客户端生成有效签名的Javascript代码...什么阻止任何人“篡改”数据然后为其生成有效签名?

一些有意义的事情:

您在hidden表单元素中向用户提供数据,并且您希望在服务器→客户端→服务器时检查用户是否未更改此值; 在这种情况下,您可以使用哈希和秘密对其进行签名,只有服务器知道并以这种方式验证它。 这里的关键是服务器上有一个秘密组件,客户端没有,也不能伪装。

在上面的场景中,您还可以简单地使用会话。 在这种情况下,您将数据防篡改存储在服务器本身,客户端根本无法访问。 上述签名方法的优点是它使服务器保持无状态,而对于服务器必须存储状态的会话。 尽管如此,他们都朝着同一个方向努力。

您希望防止第三方在从客户端向您传输数据时篡改数据。 解决此问题的唯一现实方法是使用SSL / TLS安全连接。 这允许客户端和服务器之间的合理安全通信安全地防止第三方篡改。 客户仍然可以随时向您发送任何数据,您必须验证其是否正确; 签字等等,在这里再次无关紧要。

I am trying to make sure the user has not tamped with the data when it has been submitted.

To be very blunt: this is a very stupid reason. The user is entering data into a form and submitting it to you. They are already "tampering" with the data. It doesn't make any sense to want to sign this data in any way. Even if the "problem" of PHP being a "pre-processor" would not exist, how would this work? PHP would take the data input by the user, sign it, then submit it to itself and check the signature? You can skip this whole process and just take the input of the user, that'll have the same outcome.

You could do the signing in Javascript, but this is equally nonsense. You're providing the Javascript code which can produce a valid signature to the client... what's stopping anyone from "tampering" with the data and then producing a valid signature for it?

Something that would make sense:

You provide data to the user in a hidden form element and you want to check that the user did not alter this value while it was going server→client→server; in this case you can sign it with a hash and a secret which only the server knows and verify it this way. The key here is that there's a secret component on the server that the client doesn't have and can't fake.

In the above scenario, you can also simply use sessions. In this case you're storing the data tamper-proof on the server itself where the client has no access at all. The advantage of the above signing approach is that it keeps the server stateless, while with sessions the server has to store state. They're both working towards the same end though.

You want to prevent third parties from tampering with the data while it's transmitted from the client to you. The only realistic way to solve this is to use a SSL/TLS secured connection. This allows reasonably secured communication between the client and the server safe from tampering by third parties. The client will still be able to send any data to you at any time which you'll have to verify for correctness; signing or such is, again, not relevant here.

2015-02-23

相关问答

好吧,显然我错了。 实际上,您必须考虑body参数来创建签名。 接下来,收集请求中包含的所有参数。 这些附加参数有两个这样的位置 - URL(作为查询字符串的一部分)和请求体。 对于每个人都在努力解决与此类似的问题,我可以推荐Twitters指南来创建一般的签名和OAuth。 请参阅以下链接 https://dev.twitter.com/oauth/overview/creating-signatures Okay, obviously I was wrong. You actually hav

...

更改Content-Disposition标头以指定与要上载的文件的实际名称匹配的文件名。 您还应该将Content-Type设置为application/zip或application/x-zip-compressed以便服务器知道上传的数据是zip文件。 $bytes = Get-Content "C:\Users\User\Test.zip" -Encoding Byte -ReadCount 0

$parameters = "

--$boundary

Content-Disposition

...

要在PHP中接收文本,您需要从请求主体获取它。 所以试试这个: <?php

$input = json_decode(file_get_contents('php://input'), true);

$text = $input["text"]

// ...

To receive the text in PHP you need to get it from request body. So try this: <?php

$input = json_decode(file_get_conten

...

from urllib import request, parse

data = parse.urlencode({"data":"Hello Word?"}).encode()

req = request.Request("http://www.naver.com", data=data) # this will make the method "POST"

resp = request.urlopen(req)

如果运行这个代码,数据包看起来像这样。 POST / HTTP/1.1

Acc

...

您需要将其作为表单发送。 喜欢这个。

此链接始终有用。 http://guides.rubyonrails.org/form_helpers.html#a-generic

...

好吧,不知道你在尝试什么,但让我给你一些指示。 Zend Request对象正好是一个包含Request的所有内容的对象。 为了使原始请求更加精确,在这方面, 请求中的元素不应改变。 在许多方面,它只是从公共来源获取值,并通过这个通用接口提供它们。 例如,方法getParams()返回它在$_GET或$_POST找到的值,即如果您的数据已通过GET或POST方法提交,您将永远不必担心。 这就是说,你不能通过Zend Request对象改变超全局,因为你永远不应该这样做。 但是,您可以直接更改它们,

...

我不认为你可以使用post_form方法添加自定义标头。 您可以使用post方法添加它。 请尝试以下代码: uri = URI("http://localhost:8080/places")

params = [{'uuid': '0514b...', 'name':'Athens'}]

headers = {

'Authorization'=>'Bearer: foobar',

'Content-Type' =>'application/json',

'Accept'=>

...

HttpClient.post期望第二个参数是POST请求的主体。 在你的例子中,你提供了Headers作为body,这不是你想要的。 您可以使用以下内容正确提供标题: return this.http.post('http://localhost:8000/api/v1/authenticate', null, options);

我在body的例子中显示为null ,但是您可能希望以某种形式包含email和password属性。 编辑:你正在混合Http和HttpClient 。 如果您打算

...

您可以将X_Requested_With标头添加到http数组的标头中,如下所示: 'header' => "Content-type: application/x-www-form-urlencoded\r\n" .

"X-Requested-With: xmlhttprequest\r\n",

You can add the X_Requested_With header to the headers of the http array like so: 'hea

...

我试图确保用户在提交数据时没有篡改数据。 非常生硬:这是一个非常愚蠢的原因。 用户正在将数据输入表单并将其提交给您。 他们已经在“篡改”数据。 想要以任何方式签署此数据没有任何意义。 即使PHP作为“预处理器”的“问题”不存在,它将如何工作? PHP会接受用户输入的数据,签名,然后将其提交给自己并检查签名? 您可以跳过整个过程,只需获取用户的输入,即可获得相同的结果。 你可以在Javascript中进行签名,但这同样是无稽之谈。 您正在提供可以为客户端生成有效签名的Javascript代码...什

...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值