很多站长朋友们都不太清楚php怎么进行post,今天小编就来给大家整理php怎么进行post,希望对各位有所帮助,具体内容如下:
本文目录一览: 1、 php post 怎么用? 2、 PHP的POST怎么用? 3、 怎么用PHP发送POST请求 php post 怎么用?i你可以用一个隐藏框把ID放在里面,然后到你提交的页面去拿隐藏框的值就OK了
PHP的POST怎么用?表单提交一般有两种方式GET、POST。
POST方式的用法如下
代码例如:文件为index.php
html代码
<form name="biaodan" method="post" action="index.php?action=ok">
姓名:<input type="text" name="name" value="">
<br>
性别:<input type="text" name="sex" value="">
<br>
<input type="submit" value="提交">
</form>
php代码
<?php
if(isset($_GET['action']) $_GET['action'] == 'ok'){
$name = $_POST['name'];
$sex = $_POST['sex'];
echo '姓名为:'.$name;
echo '<br>';
echo '性别为:'.$sex;
}
?>
怎么用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的介绍到此就结束了,不知道本篇文章是否对您有帮助呢?如果你还想了解更多此类信息,记得收藏关注本站,我们会不定期更新哦。
查看更多关于php怎么进行post php怎么进行数据库连接的详细内容...