php重構(gòu)HTTP包獲取result

目的是做一個分發(fā)的php腳本,根據(jù)客戶端的不同需求,分發(fā)到不同的功能腳本。所以需要首先檢驗客戶端發(fā)來的HTTP包中的請求類型,然后再進行分發(fā)。

創(chuàng)新互聯(lián)建站是專業(yè)的雨花臺網(wǎng)站建設(shè)公司,雨花臺接單;提供成都做網(wǎng)站、網(wǎng)站制作、成都外貿(mào)網(wǎng)站建設(shè),網(wǎng)頁設(shè)計,網(wǎng)站設(shè)計,建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進行雨花臺網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團隊,希望更多企業(yè)前來合作!

 

分發(fā)腳本:

<?php
/*
* This file is to distribute the requests  to different servers , is divided by functions
* Para : Http-Request
* Data : 2014.5.5
*/
// include the mapping-array
include './mapping/RequestType.php';
include './mapping/MappingTable.php';
// Get functionName from clients
$functionName = $_POST['functionName'];
// include the ReBuildHttpBag function
include 'ReBuildHttpBag.php';
// Generate the para needed
$curPageName = "/WinPhone/Distribute.php";
$desPageName = $mapping[$functionName]['pageName'];
$serverPath = $mapping[$functionName]['serverPath'];
$serverPort = 80;
ReBuildHttpBag($_GET, $curPageName, $desPageName, $serverPath, $serverPort);
?>

 

ReBuildHttpBag定義:

<?php
function ReBuildHttpBag($argv=array(), $curPageName, $desPageName, $serverPath , $serverPort)
{
$flag = 0;
$post = '';
$errno = '';
$errstr = '';
//構(gòu)造要post的字符串
foreach ($argv as $key=>$value) {
if ($flag!=0) {
$post .= "&";
$flag = 1;
}
$post.= $key."=";
$post.= urlencode($value);
$flag = 1;
}
$length = strlen($post);
//創(chuàng)建socket連接
$fp = fsockopen($serverPath,$serverPort,$errno,$errstr,10) or exit($errstr."--->".$errno);
//構(gòu)造post請求的頭
$header  = "POST ".$desPageName." HTTP/1.1\r\n";
$header .= "Host:".$serverPath."\r\n";
$header .= "Referer: ".$curPageName." \r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: ".$length."\r\n";
$header .= "Connection: Close\r\n\r\n";
//添加post的字符串
$header .= $post."\r\n";
//發(fā)送post的數(shù)據(jù)
fputs($fp,$header);
$inheader = 1;
while (!feof($fp)) {
$line = fgets($fp,1024); //去除請求包的頭只顯示頁面的返回數(shù)據(jù)
if ($inheader && ($line == "\n" || $line == "\r\n")) {
$inheader = 0;
}
if ($inheader == 0) {
echo $line;
}
}
fclose($fp);
}
?>

 

當前名稱:php重構(gòu)HTTP包獲取result
文章分享:http://muchs.cn/article40/jehieo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供云服務(wù)器網(wǎng)站內(nèi)鏈、微信小程序、網(wǎng)站排名、網(wǎng)頁設(shè)計公司軟件開發(fā)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站建設(shè)網(wǎng)站維護公司