php怎么处理服务器发回的post包

php怎么处理服务器发回的post包,第1张

至少有两种方案。

(1)不使用POST,而使用session,将php类代码处理过的数据存储在session中,然后header到example.php去取session.(推荐此方法

(2)人工构造一个POST请求,可以在百度上搜索php模拟POST提交,找到具体的方法。

------------------

问题塌磨败补充:Session是存放在服务端的,在一次会团颤话中是不会自动销毁。

我要在这一次传送结束之后就自动销毁掉,减轻服务器压力。

================

不会自动销毁,可以手游衫动销毁的。从session取到内容后,就可以使用unset($_SESSION['变量'])来销毁。

本文实例讲述了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=array()){//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

}

}

$url='http://******/con/Inter.php'

$data=Request::post($url,array('api'=>'tag_list'))

$data2=Request::post2($url,array('api'=>'tag_list'))

echo

$data

希望本文所述对大家的php程序设计有所帮助。

表单提交一般有两种方式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

}

?>


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/12285632.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-22
下一篇2023-05-22

发表评论

登录后才能评论

评论列表(0条)

    保存