四虎精品视频-四虎精品成人免费网站-四虎黄色网-四虎国产视频-国产免费91-国产蜜臀97一区二区三区

php模擬post行為代碼總結(jié)(POST方式不是絕對(duì)安全)

這里提供兩種方法供選擇:第一:手寫代碼。第二:利用HttpClient php類庫
  第一種方法:
復(fù)制代碼 代碼如下:
<?php
$flag = 0;
//要post的數(shù)據(jù)
$argv = array(
'var1'=>'abc',
'var2'=>'你好嗎');
//構(gòu)造要post的字符串
foreach ($argv as $key=>$value) {
if ($flag!=0) {
$params .= "&";
$flag = 1;
}
$params.= $key."="; $params.= urlencode($value);
$flag = 1;
}
$length = strlen($params);
//創(chuàng)建socket連接
$fp = fsockopen("127.0.0.1",80,$errno,$errstr,10) or exit($errstr."--->".$errno);
//構(gòu)造post請(qǐng)求的頭
$header = "POST /mobile/try.php HTTP/1.1";
$header .= "Host:127.0.0.1";
$header .= "Referer:/mobile/sendpost.php";
$header .= "Content-Type: application/x-www-form-urlencoded";
$header .= "Content-Length: ".$length."";
$header .= "Connection: Close";
//添加post的字符串
$header .= $params."";
//發(fā)送post的數(shù)據(jù)
fputs($fp,$header);
$inheader = 1;
while (!feof($fp)) {
$line = fgets($fp,1024); //去除請(qǐng)求包的頭只顯示頁面的返回?cái)?shù)據(jù)
if ($inheader && ($line == "n" || $line == "")) {
$inheader = 0;
}
if ($inheader == 0) {
echo $line;
}
}
fclose($fp);
?>

  第二種方法是:使用httpclient類
復(fù)制代碼 代碼如下:
$pageContents = HttpClient::quickPost('http://example.com/someForm', array(
'name' => 'Some Name',
'email' => 'email@example.com'
));

  使用httpclient類庫,可以去官方下載最新的類庫,官方地址為:http://scripts.incutio.com/httpclient/index.php
  附加一些點(diǎn)php httpclient的其他幾個(gè)用法
  靜態(tài)方法獲取網(wǎng)頁:
復(fù)制代碼 代碼如下:
$pageContents = HttpClient::quickGet('http://bankcha.com')

  Get方法獲取
復(fù)制代碼 代碼如下:
$client = new HttpClient('bankcha.com');
if (!$client->get('/')) {
die('An error occurred: '.$client->getError());
}
$pageContents = $client->getContent();
  帶調(diào)試的Get方法獲取
  php代碼
$client = new HttpClient('bankcha.com');
$client->setDebug(true);
if (!$client->get('/')) {
die('An error occurred: '.$client->getError());
}
$pageContents = $client->getContent();
  帶自動(dòng)轉(zhuǎn)向的Get方法
  php代碼
  $client = new HttpClient('www.bankcha.com');
$client->setDebug(true);
if (!$client->get('/')) {
die('An error occurred: '.$client->getError());
}
$pageContents = $client->getContent();
  檢查頁面是否存在
  php代碼
$client = new HttpClient('bankcha.com');
$client->setDebug(true);
if (!$client->get('/thispagedoesnotexist')) {
die('An error occurred: '.$client->getError());
}
if ($client->getStatus() == '404') {
echo 'Page does not exist!';
}
$pageContents = $client->getContent();
  偽造客戶端
  php代碼
$client = new HttpClient('bankcha.com');
$client->setDebug(true);
$client->setUserAgent('Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.3a) Gecko/20021207');
if (!$client->get('/')) {
die('An error occurred: '.$client->getError());
}
$pageContents = $client->getContent();
  登錄驗(yàn)證并請(qǐng)求一個(gè)網(wǎng)頁
  php代碼
$client = new HttpClient('bankcha.com');
$client->post('/login.php', array(
'username' => 'Simon',
'password' => 'ducks'
));
if (!$client->get('/private.php')) {
die('An error occurred: '.$client->getError());
}
$pageContents = $client->getContent();
  HTTP授權(quán)
  php代碼
$client = new HttpClient('bankcha.com');
$client->setAuthorization('Username', 'Password');
if (!$client->get('/')) {
die('An error occurred: '.$client->getError());
}
$pageContents = $client->getContent();
  輸出頭信息
  php代碼
$client = new HttpClient('bankcha.com');
if (!$client->get('/')) {
die('An error occurred: '.$client->getError());
}
print_r($client->getHeaders());
  設(shè)置一個(gè)域內(nèi)重定向最多次數(shù)
  php代碼
$client = new HttpClient('www.bankcha.com');
$client->setDebug(true);
$client->setMaxRedirects(3);
$client->get('/');

php fsockopen 偽造 post和get方法
fsockopen 偽造 post和get方法哦,如果你正在找 偽造 post和get方法的php處理代碼這款不錯(cuò)哦。
復(fù)制代碼 代碼如下:
<?php
//fsocket模擬post提交
$purl = "http://localhost/NETphp/test2.php?uu=rrrrrrrrrrrr";
print_r(parse_url($url));
sock_post($purl,"uu=55555555555555555");
//fsocket模擬get提交
function sock_get($url, $query)
{
$info = parse_url($url);
$fp = fsockopen($info["host"], 80, $errno, $errstr, 3);
$head = "GET ".$info['path']."?".$info["query"]." HTTP/1.0rn";
$head .= "Host: ".$info['host']."rn";
$head .= "rn";
$write = fputs($fp, $head);
while (!feof($fp))
{
$line = fread($fp,4096);
echo $line;
}
}
sock_post($purl,"uu=rrrrrrrrrrrrrrrr");
function sock_post($url, $query)
{
$info = parse_url($url);
$fp = fsockopen($info["host"], 80, $errno, $errstr, 3);
$head = "POST ".$info['path']."?".$info["query"]." HTTP/1.0rn";
$head .= "Host: ".$info['host']."rn";
$head .= "Referer: http://".$info['host'].$info['path']."rn";
$head .= "Content-type: application/x-www-form-urlencodedrn";
$head .= "Content-Length: ".strlen(trim($query))."rn";
$head .= "rn";
$head .= trim($query);
$write = fputs($fp, $head);
while (!feof($fp))
{
$line = fread($fp,4096);
echo $line;
}
}
?>

php技術(shù)php模擬post行為代碼總結(jié)(POST方式不是絕對(duì)安全),轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: hereweare| 男生虐茎虐睾视频网站| 我的爷爷 电影| 我的学生妈妈| 新民歌| 九龙城寨在线观看| 血糖最怕三种水果| 温子仁电影| 动漫秀场| 七年级的英语翻译全书| 刘德华的歌曲经典| reimei影虎| 中川翔子| 次元舰队| 教育向美而生读书心得体会| 男同视频在线| 热巴电视剧在线观看免费| 液氨化学性质| 第一次美国电影| 彻夜狂欢| 帐篷里的小秘密免费全集| 超级大山炮之海岛奇遇 电影免费观看| 光彩年华| 哈尔的移动城堡电影| 小学生版《三国演义》| 小孩打屁股| 蜡笔小新日文| 妈妈的花样年华演员表全部| 涩谷天马| 手机图标大全| 红电视剧演员表| 50字精美优秀教师个人简介| av网址大全| x档案第二季| city of stars歌词| 四年级下册语文猫课堂笔记| 诊所惊魂| 狼来了ppt免费下载| 森林运动会作文三年级300字| 俺去也电影网| 大奉打更人电视剧在线观看全集免费播放 |