PHP 模倣 ASP xmlhttprequest リクエスト データ コード_PHP チュートリアル
クラス名: httprequest($url="",$method="get",$usesocket=0)
//$url は要求されたアドレスです。$usesocket のデフォルトは 0 で、fsockopen を使用します。 Method、1 に設定した場合は、socket_create メソッドを使用します
Method:
open($ip="",$port=-1) //同じサーバーへの接続を開きます。デフォルトでは、これらを設定する必要はありません。 2 つのパラメーター (同僚が Linux で使用する場合)、リクエストはホスト名によって解決された IP ではないため、これら 2 つのパラメーターは実際のサーバー IP に接続するために追加されます)
settimeout($timeout=0) // のタイムアウトを設定しますデータの取得。有効にするには、send メソッドが呼び出される前に設定する必要があります。単位は秒です。デフォルト値 0 は無制限です
setrequestheader($key,$value="") // リクエスト ヘッダーを設定します。これは設定する必要があります。 send メソッドが呼び出される前に有効になります
removerequestheader($key,$value="") / / 指定されたキー値のリクエスト ヘッダーを削除します。有効にするためには send メソッドが呼び出される前に呼び出す必要があります
send($ data="") //データ $data をサーバーに送信
getresponsebody() //サーバーから返されたテキストを取得
getallresponseheaders( ) //サーバー応答のすべてのヘッダー情報を取得
getresponseheader($key) //Getサーバー応答の特定のヘッダー情報 (server、set_cookie など)
属性:
$url //リクエストされる URL
$method //リクエスト メソッド (post/get)
$port //リクエストされたポート
$hostname //リクエストされたホスト名
$uri //urlのファイル部分
$protocol //リクエストプロトコル(http)(この属性の上記5つを含む属性はURLを通じてプログラムによって自動的に解析されます)
$excption / /例外情報
$_headers=array() //リクエストヘッダ array("key"=>"value")
$_senddata //サーバーに送信されたデータ
$status //返されたステータスコード
$statustext //ステータス情報
$httpprotocolversion //サーバーの http プロトコルのバージョン
注:
post メソッドでリクエストする場合、ホストヘッダーはプログラムによって自動的に設定されます。content-length と content-type は自動的に設定されます。
サポート gzip 圧縮ページ
inc.http.php チュートリアル ファイル
class httprequest{
public $url,$method,$port,$hostname,$uri,$protocol,$excption,$_headers=array(),$_senddata,$status,$statustext,$httpprotocolversion;
private $fp =0,$_buffer="",$responsebody,$responseheader,$timeout=0,$usesocket;
//构造関数数
function __construct($url="",$method="get",$usesocket=0) {
$this->url = $url;
$this->method = strtoupper($method);
$this->usesocket = $usesocket;
$this->setrequestheader("accept"," */*");
$this->setrequestheader("accept- language","zh-cn");
$this->setrequestheader("accept-encoding","gzip, deflate");
$ this->setrequestheader("user-agent","httprequest class 1.0"); //可调用setrequestheader来修正
}
//接服务器
public function open($ip="",$port=-1){
if(!$this->_geturlinfo()) return false;
$this->setrequestheader("host",$this->hostname);
$this->setrequestheader("connection","close");
$ip = ($ip=="" ? $this ->ホスト名 : $ip);
$port = ($port==-1 ? $this->ポート : $port);
if($this->usesocket==1){
if(! $this->fp=$socket=socket_create(af_inet,sock_stream,0)) {
$this->excption="ソケットを作成できません";return false;
}else{
if(!socket_connect($this ->fp,$ip, $port) ){
$this->excption="サーバー " に接続できません。 $this->ホスト名 。 「ポート上」。 $this->port;return false;
}
}
}else{
if(!$this->fp=fsockopen($ip, $port,$errno,$errstr,10)) {
$this ->excption="サーバーに接続できません" 。 $this->ホスト名 。 「ポート上」。 $this->port;return false;
}
}
return true;
}
public function send($data=""){
if(!$this->fp){$this-> excption="はリソース ID ではありません";return false;}
if($this->method=="get" && $data!=""){
$s_str="?";
if(strpos( $this->uri,"?")>0) $s_str = "&";
$this->uri.= $s_str 。 $data;
$data="";
}
$senddata=$this->メソッド 。 「」。 $this->uri 。 " http/1.1rn";
if($this->method=="post"){
$this->setrequestheader("content-length",strlen($data));
$this-> setrequestheader("content-type", "application/x-www-form-urlencoded");
}
foreach($this->_headers as $keys => $value){
$senddata .= "$keys : $valuern";
}
$senddata .= "rn";
if($this->method=="post") $senddata .= $data;
$this->_senddata = $senddata;
if($this->usesocket==1){
socket_write($this->fp,$this->_senddata);
$buffer="";
$timestart = time();
do{
if($this->timeout>0){
if(time()-$timestart>$this->timeout){break;}
}
$this->_buffer.=$buffer;
$buffer =socket_read($this->fp,4096);
}while($buffer!="");
socket_close($this->fp);
}else{
fputs($this->fp, $senddata);
$this->gt;_buffer="";
$timestart = time();
while(!feof($this->fp) )
{
if($this->timeout>0){
if(time()-$timestart>$this->timeout){break;}
}
$this->gt;_buffer.=fgets( $this->fp,4096);
}
fclose($this->fp);
}
$this->_splitcontent();
$this->_getheaderinfo();
}
public function getresponsebody(){
if($this->getresponseheader("content-encoding")== "gzip" && $this->getresponseheader("transfer-encoding")=="chunked"){
return gzdecode_1(transfer_encoding_chunked_decode($this->responsebody));
}else if($this->getresponseheader ("content-encoding")=="gzip"){
return gzdecode_1($this->responsebody);
}else{
return $this->responsebody;
}
}
public function getallresponseheaders() {
return $this->responseheader;
}
public function getresponseheader($key){
$key = str_replace("-","-",$key);
$headerstr = $this->responseheader 。 "rn";
$count = preg_match_all("/n$key:(.+?)r/is",$headerstr,$result,preg_set_order);
if($count>0){
$returnstr="" ;
foreach($result as $key1=>$value){
if(strtoupper($key)=="set-cookie"){
$value[1] = substr($value[1],0, strpos($value[1],";"));
}
$returnstr .= ltrim($value[1]) 。 "; ";
}
$returnstr = substr($returnstr,0,strlen($returnstr)-2);
return $returnstr;
}else{return "";}
}
public function settimeout($timeout =0){
$this->timeout = $timeout;
}
public function setrequestheader($key,$value=""){
$this->_headers[$key]=$value;
}
public function Removerequestheader($key){
if(count( $this->_headers)==0){return;}
$_temp=array();
foreach($this->_headers as $keys => $value){
if($keys!=$ key){
$_temp[$keys]=$value;
}
}
$this->_headers = $_temp;
}
//拆分url
private function _geturlinfo(){
$url = $ this->url;
$count = preg_match("/^http://([^:/]+?)(:(d+))?/(.+?)$/is",$url,$ result);
if($count>0){
$this->uri="/" . $result[4];
}else{
$count = preg_match("/^http://([^:/]+?)(:(d+))?(/)?$/is",$url ,$result);
if($count>0){
$this->uri="/";
}
}
if($count>0){
$this->protocol="http" ;
$this->hostname=$result[1];
if(isset($result[2]) && $result[2]!="") {$this->port=intval($result[ 3]);}else{$this->port=80;}
return true;
}else{$this->excption="url 形式エラー";return false;}
}
private function _splitcontent( ){
$this->responseheader="";
$this->responsebody="";
$p1 = strpos($this->_buffer,"rnrn");
if($p1>0) {
$this->responseheader = substr($this->gt;_buffer,0,$p1);
if($p1+4_buffer)){
$this->responsebody = substr($this->_buffer,$p1+4);
}
}
}
プライベート関数 _getheaderinfo(){
$headerstr = $this->responseheader;
$count = preg_match("/^ http/(.+?)s(d+)s(.+?)rn/is",$headerstr,$result);
if($count>0){
$this->httpprotocolversion = $result[1 ];
$this->status = intval($result[2]);
$this->statustext = $result[3];
}
}
}
//以下两関数数参考网络
function gzdecode_1 ($data) {
$data = ($data);
if (!function_exists ( 'gzdecode' )) {
$flags = ord ( substr ( $data, 3 , 1 ) );
$headerlen = 10;
$extralen = 0;
$filenamelen = 0;
if ($flags & 4) {
$extralen = unpack ( 'v', substr ( $data, 10, 2 ) );
$extralen = $extralen [1];
$headerlen += 2 + $extralen;
}
if ($flags & 8) // ファイル名
$headerlen = strpos ( $data, chr ( 0 ), $headerlen ) + 1;
if ($flags & 16) // コメント
$headerlen = strpos ( $data, chr ( 0 ), $headerlen ) + 1;
if ($flags & 2) // 末尾に crcファイルの
$headerlen += 2;
$unpacked = @gzinflate ( substr ( $data, $headerlen ) );
if ($unpacked === false)
$unpacked = $data;
return $unpacked;
} else{
return gzdecode($data);
}
}function transfer_encoding_chunked_decode($in) {
$out = "";
while ( $in !="") {
$lf_pos = strpos ( $in, "12" );
if ($lf_pos === false) {
$out .= $in;
break;
}
$chunk_hex = トリム ( substr ( $in, 0, $lf_pos ) );
$sc_pos = strpos ( $chunk_hex, ';' );
if ($sc_pos !== false)
$chunk_hex = substr ( $chunk_hex, 0, $sc_pos );
if ($chunk_hex =="") {
$out .= substr ( $in, 0, $lf_pos );
$in = substr ( $in, $lf_pos + 1 );
続行;
}
$chunk_len = hexdec ( $chunk_hex );
if ($chunk_len) {
$out .= substr ( $in, $lf_pos + 1, $chunk_len );
$in = substr ( $in, $lf_pos + 2 + $chunk_len );
} else {
$in = "";
}
}
return $out;
}
function utf8togb($str){
return iconv("utf-8","gbk",$str);
}function gbtoutf8($str){
return iconv( "gbk","utf-8",$str);
}
?>
response.asp教程文件
<%
response.cookies("a") = "anlige"
response.cookies ("a").expires = dateadd("yyyy",1,now())
response.cookies("b")("c") = "wsdasdadsa"
response.cookies("b")("d ") = "ddd"
response.cookies("b").expires = dateadd("yyyy",1,now())
response.write "querystring : " & request.querystring & "
"
request.querystring の各 v について
response.write v & "=" & request.querystring(v) & "
"
next
response.write "
form : " & request.form & "
"
request.form の各 v について
response.write v & "=" & request.form(v) & "
"
次の
response .write "
url : " & request.servervariables("url") & "
"
response.write "referer : " & request.servervariables("http_referer") & "< ;br />gt;"
response.write "host : " & request.servervariables("http_host") & "
gt;"
response.write "user-agent : " & request.servervariables("http_user_agent" ) & "
"
response.write "cookie" & request.servervariables("http_cookie")
%>
index.php文件
転送データを取得
転送データを送信
ソース情報をサーバーに送信
ユーザーエージェントをサーバーに送信
サーバーから返されたステータスを取得します
サーバーの応答ヘッダーを取得します
画像を保存
include("inc_http.php");
$responseurl = " http: //dev.mo.cn/aiencode/http/response.asp";$act = isset($_get["action"]) ? $_get["action"] : "";
if($ act = = "get"){ //データを取得$myhttp = new httprequest("$responseurl?a=text");
$myhttp->open();
$myhttp->send(" name=anlige&city =" . urlencode("杭州"));
echo($myhttp->getresponsebody());
}else if($act == "post"){ //データを投稿$ myhttp = new httprequest ("$responseurl?a=text","post");
$myhttp->open();
$myhttp->send("name=anlige&city=" . urlencode("杭州") );
echo ($myhttp->getresponsebody());
}else if($act == "header_referer"){ //ソース情報をサーバーに送信します$myhttp = new httprequest("$responseurl? a=text" ,"投稿");
$myhttp->open();
$myhttp->setrequestheader("リファラー","http://www.baidu.com");
$myhttp->send(" name=anlige&city=" . urlencode("Hangzhou"));
echo($myhttp->getresponsebody());
}else if($act == "header_useragent"){ //サーバーに ユーザーを送信します-エージェント$myhttp = new httprequest("$responseurl?a=text","post");
$myhttp->open();
$myhttp->setrequestheader("referer","http :// www.baidu.com");
$myhttp->setrequestheader("user-agent","mozilla/4.0 (互換性; msie 7.0; windows nt 6.0; trident/4.0)");
$myhttp->send ("name=anlige&city=" . urlencode("杭州"));
echo($myhttp->getresponsebody());
}else if($act == "status"){ // によって返されるステータスを取得しますサーバー$myhttp = new httprequest("$responseurl?a=text","post");
$myhttp->open();
$myhttp->send("name=anlige&city=" . urlencode ("杭州"));
echo($myhttp->ステータス . " " . $myhttp->ステータステキスト ."
");
echo($myhttp -> ;getresponsebody());
}else if($act == "get_headers"){ //サーバーの応答ヘッダーを取得します$myhttp = new httprequest("$responseurl?a=text","get") ;
$myhttp->open();
$myhttp->send("name=anlige&city=" . urlencode("杭州"));
echo($myhttp->getallresponseheaders()."
");
echo($myhttp->getresponseheader("server")."
");
}else if($act == "get_image"){
$myhttp = new httprequest("http://www.baidu.com/img/baidu_logo.gif");
$myhttp->open();
$myhttp-> ; send();
$fp = @fopen("demo.gif","w");
fwrite($fp,$myhttp->getresponsebody());
fclose($fp);
echo(" < ;img src="demo.gif" />");
}
?>

ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

AI Hentai Generator
AIヘンタイを無料で生成します。

人気の記事

ホットツール

メモ帳++7.3.1
使いやすく無料のコードエディター

SublimeText3 中国語版
中国語版、とても使いやすい

ゼンドスタジオ 13.0.1
強力な PHP 統合開発環境

ドリームウィーバー CS6
ビジュアル Web 開発ツール

SublimeText3 Mac版
神レベルのコード編集ソフト(SublimeText3)

ホットトピック









PHP 8.4 では、いくつかの新機能、セキュリティの改善、パフォーマンスの改善が行われ、かなりの量の機能の非推奨と削除が行われています。 このガイドでは、Ubuntu、Debian、またはその派生版に PHP 8.4 をインストールする方法、または PHP 8.4 にアップグレードする方法について説明します。

Visual Studio Code (VS Code とも呼ばれる) は、すべての主要なオペレーティング システムで利用できる無料のソース コード エディター (統合開発環境 (IDE)) です。 多くのプログラミング言語の拡張機能の大規模なコレクションを備えた VS Code は、

あなたが経験豊富な PHP 開発者であれば、すでにそこにいて、すでにそれを行っていると感じているかもしれません。あなたは、運用を達成するために、かなりの数のアプリケーションを開発し、数百万行のコードをデバッグし、大量のスクリプトを微調整してきました。

このチュートリアルでは、PHPを使用してXMLドキュメントを効率的に処理する方法を示しています。 XML(拡張可能なマークアップ言語)は、人間の読みやすさとマシン解析の両方に合わせて設計された多用途のテキストベースのマークアップ言語です。一般的にデータストレージに使用されます

JWTは、JSONに基づくオープン標準であり、主にアイデンティティ認証と情報交換のために、当事者間で情報を安全に送信するために使用されます。 1。JWTは、ヘッダー、ペイロード、署名の3つの部分で構成されています。 2。JWTの実用的な原則には、JWTの生成、JWTの検証、ペイロードの解析という3つのステップが含まれます。 3. PHPでの認証にJWTを使用する場合、JWTを生成および検証でき、ユーザーの役割と許可情報を高度な使用に含めることができます。 4.一般的なエラーには、署名検証障害、トークンの有効期限、およびペイロードが大きくなります。デバッグスキルには、デバッグツールの使用とロギングが含まれます。 5.パフォーマンスの最適化とベストプラクティスには、適切な署名アルゴリズムの使用、有効期間を合理的に設定することが含まれます。

文字列は、文字、数字、シンボルを含む一連の文字です。このチュートリアルでは、さまざまな方法を使用してPHPの特定の文字列内の母音の数を計算する方法を学びます。英語の母音は、a、e、i、o、u、そしてそれらは大文字または小文字である可能性があります。 母音とは何ですか? 母音は、特定の発音を表すアルファベットのある文字です。大文字と小文字など、英語には5つの母音があります。 a、e、i、o、u 例1 入力:string = "tutorialspoint" 出力:6 説明する 文字列「TutorialSpoint」の母音は、u、o、i、a、o、iです。合計で6元があります

静的結合(静的::) PHPで後期静的結合(LSB)を実装し、クラスを定義するのではなく、静的コンテキストで呼び出しクラスを参照できるようにします。 1)解析プロセスは実行時に実行されます。2)継承関係のコールクラスを検索します。3)パフォーマンスオーバーヘッドをもたらす可能性があります。

PHPの魔法の方法は何ですか? PHPの魔法の方法には次のものが含まれます。1。\ _ \ _コンストラクト、オブジェクトの初期化に使用されます。 2。\ _ \ _リソースのクリーンアップに使用される破壊。 3。\ _ \ _呼び出し、存在しないメソッド呼び出しを処理します。 4。\ _ \ _ get、dynamic属性アクセスを実装します。 5。\ _ \ _セット、動的属性設定を実装します。これらの方法は、特定の状況で自動的に呼び出され、コードの柔軟性と効率を向上させます。
