很多站长朋友们都不太清楚php异步post请求,今天小编就来给大家整理php异步post请求,希望对各位有所帮助,具体内容如下:
本文目录一览: 1、 PHP。POST请求的问题 2、 如何用php向服务器发送post请求 3、 怎么用PHP发送POST请求 4、 php中超级链接如何使用post方法传递参数 PHP。POST请求的问题最简单的话就是使用session保存,其次可以把数据存储在数据库里,或者文件里,然后在register.php里查询。
原生session使用方法
session_start();
//赋值
$_SESSION["Session名称"]=变量或字符串信息;
//使用
$_SESSION["Session名称"];
如何用php向服务器发送post请求用PHP向服务器发送HTTP的POST请求,代码如下:
<?php
/**
* 发送post请求
* @param string $url 请求地址
* @param array $post_data post键值对数据
* @return string
*/
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,
'timeout' => 15 * 60 // 超时时间(单位:s)
)
);
$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请求PHP发送POST请求的三种方式
class Request{
public static function post($url, $post_data = '', $timeout = 5){//curl
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_POST, 1);
if($post_data != ''){
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
}
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_HEADER, false);
$file_contents = curl_exec($ch);
curl_close($ch);
return $file_contents;
}
public static function post2($url, $data){//file_get_content
$postdata = http_build_query(
$data
);
$opts = array('http' =>
array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $postdata
)
);
$context = stream_context_create($opts);
$result = file_get_contents($url, false, $context);
return $result;
}
public static function post3($host,$path,$query,$others=''){//fsocket
$post="POST $path HTTP/1.1\r\nHost: $host\r\n";
$post.="Content-type: application/x-www-form-";
$post.="urlencoded\r\n${others}";
$post.="User-Agent: Mozilla 4.0\r\nContent-length: ";
$post.=strlen($query)."\r\nConnection: close\r\n\r\n$query";
$h=fsockopen($host,80);
fwrite($h,$post);
for($a=0,$r='';!$a;){
$b=fread($h,8192);
$r.=$b;
$a=(($b=='')?1:0);
}
fclose($h);
return $r;
}
}
php中超级链接如何使用post方法传递参数表单直接传递,代码如下!
创建go.php 文件中的代码如下!
<?php
@$name = $_POST['name'];
if(!empty($name)){
echo $name;
}else{
echo '<form action="go.php" method="post">
<input type="text" name="name">
<button>提交</button>
</form>';
}
?>
代码解释
@$name = $_POST['name'];
@错误抑制
1、常见变量$name = post过来的name值
2、empty($name)检查是否为空,在前面加上!表示不为空,不为空就显示$name的值
3、为空显示表单
4、action="go.php"表示表单填写的值将传递到,go.php
5、method="post" 表示传递方式为post
6、<input type="text" name="name">文本输入框
7、<button>提交</button> 提交按钮
关于php异步post请求的介绍到此就结束了,不知道本篇文章是否对您有帮助呢?如果你还想了解更多此类信息,记得收藏关注本站,我们会不定期更新哦。
查看更多关于php异步post请求 php8 异步的详细内容...