网站首页 > 文章中心 > 其它

php规范post数据_PHP获取表单数据只能用$_POST。

作者:小编 更新时间:2023-09-22 07:02:34 浏览量:148人看过

php post 提交数据

先把JS的提交函数写好,引入到test.php文件中(别说你不会......).把函数绑到按钮的onclick事件上,或者你用setInterval反复执行提交函数.

求助PHP如何POST提交数据

用PHP向服务器发送HTTP的POST请求,代码如下:

php

/**?

*?发送post请求?

*/?

function?send_post($url,?$post_data)?{?

$postdata?=?http_build_query($post_data);?

$options?=?array(?

'http'?=?array(?

'method'?=?'POST',?

'header'?=?'Content-type:application/x-www-form-urlencoded',?

'content'?=?$postdata,?

)?

);?

$context?=?stream_context_create($options);?

$result?=?file_get_contents($url,?false,?$context);???

return?$result;?

}

使用的时候直接调用上面定义的send_post方法:

$post_data?=?array(

'username'?=?'username',

'password'?=?'password'

);

send_post('网址',?$post_data);

php 接收到之后post数据写入数据库

form表单demo:task.html

fieldset id="setFiled"

legend发布任务/legend

form action="registr.php" method="post" id="steForm"

label任务类型:/labelbr

input type="text" name="type"? id="taskType" placeholder="请选择任务类型"/br

input type="text" name="type"? id="taskType" placeholder="请选择任务类型"/br

input type="text" name="type"? id="taskType" placeholder="请选择任务类型"/br

label酬nbsp;nbsp;金:/labelbr

input type="number" name="money" id="forMoney" min="1" max="1000"/label元/labelbr

label截止时间:/labelbr

input type="datetime" name="time" id="timeSubmit"/span data-year="" data-month="" data-date="" id="showDate"/spanbr

label详细描述:/labelbr

/form

扩展资料

php接收POST数据的三种方式

①.、$_POST 方式接受数据

$_POST 方式是由通过HTTP的POST方法传递过来的数据组成的数组,是一个自动全局变量.

注:只能接收Content-Type:application/x-www-form-urlencode提交的数据.也就是只能接收表单过来的数据.

如果访问原始POST数据不是php能够识别的文档类型,比如:text/xml 或者soap等等,可以用$GLOBLES['HTTP_RAW_POST_DATA']来接收,$HTTP_RAW_POST_DATA变量包含有原始POST数据.此变量仅在碰到未识别的MIME数据时产生.

注:$HTTP_RAW_POST_DATA对于enctype="multipart/form-data"表单数据不可用,也就是说使用$HTTP_RAW_POST_DATA无法接受网页表单post过来的数据.

如果访问原始POST数据,更好的方法是使用file_get_content("php://input");对于未指定Content-Type的POST数据,可以使用该方法读取POST原始数据,包括二进制流也可以和$HTTP_RAW_POST_DATA比起来.它带来的生存眼里更小,并且不需要任何特殊的php.ini设置.

注:php://input不能用于 enctype="multipart/form-data"

例如:$postStr = file_get_contents("php://input"); //获取POST数据

以上就是土嘎嘎小编为大家整理的php规范post数据相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!

版权声明:倡导尊重与保护知识产权。未经许可,任何人不得复制、转载、或以其他方式使用本站《原创》内容,违者将追究其法律责任。本站文章内容,部分图片来源于网络,如有侵权,请联系我们修改或者删除处理。

编辑推荐

热门文章