目錄
Request URL
Simple PHP Proxy response
首頁 後端開發 php教程 简略的php代理 Simple PHP Proxy

简略的php代理 Simple PHP Proxy

Jun 13, 2016 am 11:57 AM
gt json lt the url

简单的php代理 Simple PHP Proxy

实例:http://www.ikeepstudying.com/tools/proxy/

?

index.php

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><script type="text/javascript" language="javascript">// I want to use json2.js because it allows me to format stringified JSON with// pretty indents, so let's nuke any existing browser-specific JSON parser.window.JSON = null;</script><script type="text/javascript" src="/js/jquery-1.8.2.min.js"></script><script type="text/javascript" src="http://benalman.com/code/projects/php-simple-proxy/shared/json2.js"></script><script>	(function($){$(document).ready(function(e)	{		// Handle form submit.		$('#params').submit(function(){			var proxy = 'proxy.php', url = proxy + '?' + $('#params').serialize();						// Update some stuff.			$('#request').html( $('<a/>').attr( 'href', url ).text( url ) );			$('#response').html( 'Loading...' );						// Test to see if HTML mode.			if ( /mode=native/.test( url ) ) 			{			  	// Make GET request.			  	$.get( url, function(data)			  	{			  		$('#response')			  		.html( '<pre class='brush:php;toolbar:false;'>' )			  		.find( 'pre' )			  		.text( data );			  	});			} 			else 			{			  	// Make JSON request.				$.getJSON( url, function(data)				{			  		$('#response')			  		.html( '<pre class="brush:js"/>' )			  		.find( 'pre' )					.text( JSON.stringify( data, null, 2 ) );			  	});			}						// Prevent default form submit action.			return false;		});	  	  	// Submit the form on page load if ?url= is passed into the example page.	  	if ( $('#url').val() !== '' ) $('#params').submit();	  	  	// Disable AJAX caching.	  	$.ajaxSetup({ cache: false });	  	  	// Disable dependent checkboxes as necessary.	  	$('input:radio').click(function(){			var that = $(this),	  		c1 = 'dependent-' + that.attr('name'),	  		c2 = c1 + '-' + that.val();				that.closest('form')		  	.find( '.' + c1 + ' input' )			.attr( 'disabled', 'disabled' )		    .end()		  	.find( '.' + c2 + ' input' )			.removeAttr( 'disabled' );	 	});	  	  	// Clicking sample remote urls should populate the "Remote URL" box.	  	$('#sample a').click(function(){			$('#url').val( $(this).attr( 'href' ) );	    	return false;	  	});			});})($staff)</script> <form action="" method="get" id="params">  <div>    <label>      <b>Remote URL</b>      <input type="text" value="" name="url" class="text" id="url" style="width:90%" />    </label>  </div>  <p id="sample">    ..or try these sample Remote URLs:    <a href="http://github.com/">GitHub</a>,    <a href="http://github.com/cowboy/php-simple-proxy/raw/master/examples/simple/json_sample.js">a sample JSON (not JSONP) request</a>,    <a href="http://github.com/omg404errorpage">a 404 error page</a>  </p>  <div>    <label>      <input type="radio" disabled="disabled" value="native" name="mode">      Native <i>(disabled by default)</i>    </label>  </div>  <div>    <label>      <input type="radio" disabled="disabled" checked="checked" value="json" name="mode">      JSON    </label>  </div>  <div class="dependent-mode dependent-mode-json indent">    <div>      <label>        <input type="checkbox" checked="checked" value="1" name="full_headers">        Full Headers      </label>    </div>    <div>      <label>        <input type="checkbox" checked="checked" value="1" name="full_status">        Full Status      </label>    </div>  </div>  <input type="submit" value="Submit" name="submit" class="submit"></form><h3 id="Request-URL">Request URL</h3><p id="request">N/A, click Submit!</p><h3 id="Simple-PHP-Proxy-response">Simple PHP Proxy response</h3><div id="response">N/A, click Submit!</div>
登入後複製

?

proxy.php

<?PHP// Script: Simple PHP Proxy: Get external HTML, JSON and more!//// *Version: 1.6, Last updated: 1/24/2009*// // Project Home - http://benalman.com/projects/php-simple-proxy/// GitHub       - http://github.com/cowboy/php-simple-proxy/// Source       - http://github.com/cowboy/php-simple-proxy/raw/master/ba-simple-proxy.php// // About: License// // Copyright (c) 2010 "Cowboy" Ben Alman,// Dual licensed under the MIT and GPL licenses.// http://benalman.com/about/license/// // About: Examples// // This working example, complete with fully commented code, illustrates one way// in which this PHP script can be used.// // Simple - http://benalman.com/code/projects/php-simple-proxy/examples/simple/// // About: Release History// // 1.6 - (1/24/2009) Now defaults to JSON mode, which can now be changed to//       native mode by specifying ?mode=native. Native and JSONP modes are//       disabled by default because of possible XSS vulnerability issues, but//       are configurable in the PHP script along with a url validation regex.// 1.5 - (12/27/2009) Initial release// // Topic: GET Parameters// // Certain GET (query string) parameters may be passed into ba-simple-proxy.php// to control its behavior, this is a list of these parameters. // //   url - The remote URL resource to fetch. Any GET parameters to be passed//     through to the remote URL resource must be urlencoded in this parameter.//   mode - If mode=native, the response will be sent using the same content//     type and headers that the remote URL resource returned. If omitted, the//     response will be JSON (or JSONP). <Native requests> and <JSONP requests>//     are disabled by default, see <Configuration Options> for more information.//   callback - If specified, the response JSON will be wrapped in this named//     function call. This parameter and <JSONP requests> are disabled by//     default, see <Configuration Options> for more information.//   user_agent - This value will be sent to the remote URL request as the//     `User-Agent:` HTTP request header. If omitted, the browser user agent//     will be passed through.//   send_cookies - If send_cookies=1, all cookies will be forwarded through to//     the remote URL request.//   send_session - If send_session=1 and send_cookies=1, the SID cookie will be//     forwarded through to the remote URL request.//   full_headers - If a JSON request and full_headers=1, the JSON response will//     contain detailed header information.//   full_status - If a JSON request and full_status=1, the JSON response will//     contain detailed cURL status information, otherwise it will just contain//     the `http_code` property.// // Topic: POST Parameters// // All POST parameters are automatically passed through to the remote URL// request.// // Topic: JSON requests// // This request will return the contents of the specified url in JSON format.// // Request:// // > ba-simple-proxy.php?url=http://example.com/// // Response:// // > { "contents": "<html>...</html>", "headers": {...}, "status": {...} }// // JSON object properties:// //   contents - (String) The contents of the remote URL resource.//   headers - (Object) A hash of HTTP headers returned by the remote URL//     resource.//   status - (Object) A hash of status codes returned by cURL.// // Topic: JSONP requests// // This request will return the contents of the specified url in JSONP format// (but only if $enable_jsonp is enabled in the PHP script).// // Request:// // > ba-simple-proxy.php?url=http://example.com/&callback=foo// // Response:// // > foo({ "contents": "<html>...</html>", "headers": {...}, "status": {...} })// // JSON object properties:// //   contents - (String) The contents of the remote URL resource.//   headers - (Object) A hash of HTTP headers returned by the remote URL//     resource.//   status - (Object) A hash of status codes returned by cURL.// // Topic: Native requests// // This request will return the contents of the specified url in the format it// was received in, including the same content-type and other headers (but only// if $enable_native is enabled in the PHP script).// // Request:// // > ba-simple-proxy.php?url=http://example.com/&mode=native// // Response:// // > <html>...</html>// // Topic: Notes// // * Assumes magic_quotes_gpc = Off in php.ini// // Topic: Configuration Options// // These variables can be manually edited in the PHP file if necessary.// //   $enable_jsonp - Only enable <JSONP requests> if you really need to. If you//     install this script on the same server as the page you're calling it//     from, plain JSON will work. Defaults to false.//   $enable_native - You can enable <Native requests>, but you should only do//     this if you also whitelist specific URLs using $valid_url_regex, to avoid//     possible XSS vulnerabilities. Defaults to false.//   $valid_url_regex - This regex is matched against the url parameter to//     ensure that it is valid. This setting only needs to be used if either//     $enable_jsonp or $enable_native are enabled. Defaults to '/.*/' which//     validates all URLs.// // ############################################################################// Change these configuration options if needed, see above descriptions for info.$enable_jsonp    = false;$enable_native   = false;$valid_url_regex = '/.*/';// ############################################################################$url = $_GET['url'];if ( !$url ) {    // Passed url not specified.  $contents = 'ERROR: url not specified';  $status = array( 'http_code' => 'ERROR' );  } else if ( !preg_match( $valid_url_regex, $url ) ) {    // Passed url doesn't match $valid_url_regex.  $contents = 'ERROR: invalid url';  $status = array( 'http_code' => 'ERROR' );  } else {  $ch = curl_init( $url );    if ( strtolower($_SERVER['REQUEST_METHOD']) == 'post' ) {    curl_setopt( $ch, CURLOPT_POST, true );    curl_setopt( $ch, CURLOPT_POSTFIELDS, $_POST );  }    if ( $_GET['send_cookies'] ) {    $cookie = array();    foreach ( $_COOKIE as $key => $value ) {      $cookie[] = $key . '=' . $value;    }    if ( $_GET['send_session'] ) {      $cookie[] = SID;    }    $cookie = implode( '; ', $cookie );        curl_setopt( $ch, CURLOPT_COOKIE, $cookie );  }    curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );  curl_setopt( $ch, CURLOPT_HEADER, true );  curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );    curl_setopt( $ch, CURLOPT_USERAGENT, $_GET['user_agent'] ? $_GET['user_agent'] : $_SERVER['HTTP_USER_AGENT'] );    list( $header, $contents ) = preg_split( '/([\r\n][\r\n])\\1/', curl_exec( $ch ), 2 );    $status = curl_getinfo( $ch );    curl_close( $ch );}// Split header text into an array.$header_text = preg_split( '/[\r\n]+/', $header );if ( $_GET['mode'] == 'native' ) {  if ( !$enable_native ) {    $contents = 'ERROR: invalid mode';    $status = array( 'http_code' => 'ERROR' );  }    // Propagate headers to response.  foreach ( $header_text as $header ) {    if ( preg_match( '/^(?:Content-Type|Content-Language|Set-Cookie):/i', $header ) ) {      header( $header );    }  }    print $contents;  } else {    // $data will be serialized into JSON data.  $data = array();    // Propagate all HTTP headers into the JSON data object.  if ( $_GET['full_headers'] ) {    $data['headers'] = array();        foreach ( $header_text as $header ) {      preg_match( '/^(.+?):\s+(.*)$/', $header, $matches );      if ( $matches ) {        $data['headers'][ $matches[1] ] = $matches[2];      }    }  }    // Propagate all cURL request / response info to the JSON data object.  if ( $_GET['full_status'] ) {    $data['status'] = $status;  } else {    $data['status'] = array();    $data['status']['http_code'] = $status['http_code'];  }    // Set the JSON data object contents, decoding it from JSON if possible.  $decoded_json = json_decode( $contents );  $data['contents'] = $decoded_json ? $decoded_json : $contents;    // Generate appropriate content-type header.  $is_xhr = strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest';  header( 'Content-type: application/' . ( $is_xhr ? 'json' : 'x-javascript' ) );    // Get JSONP callback.  $jsonp_callback = $enable_jsonp && isset($_GET['callback']) ? $_GET['callback'] : null;    // Generate JSON/JSONP string  $json = json_encode( $data );    print $jsonp_callback ? "$jsonp_callback($json)" : $json;  }
登入後複製

?

实例:http://www.ikeepstudying.com/tools/proxy/

原文:http://benalman.com/projects/php-simple-proxy/

?

?

?

本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

<🎜>:泡泡膠模擬器無窮大 - 如何獲取和使用皇家鑰匙
3 週前 By 尊渡假赌尊渡假赌尊渡假赌
北端:融合系統,解釋
3 週前 By 尊渡假赌尊渡假赌尊渡假赌
Mandragora:巫婆樹的耳語 - 如何解鎖抓鉤
3 週前 By 尊渡假赌尊渡假赌尊渡假赌

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

熱門話題

Java教學
1665
14
CakePHP 教程
1424
52
Laravel 教程
1322
25
PHP教程
1270
29
C# 教程
1249
24
華為GT3 Pro和GT4的差異是什麼? 華為GT3 Pro和GT4的差異是什麼? Dec 29, 2023 pm 02:27 PM

許多用戶在選擇智慧型手錶的時候都會選擇的華為的品牌,其中華為GT3pro和GT4都是非常熱門的選擇,不少用戶都很好奇華為GT3pro和GT4有什麼區別,下面就給大家介紹一下二者。華為GT3pro和GT4有什麼差別一、外觀GT4:46mm和41mm,材質是玻璃鏡板+不鏽鋼機身+高分纖維後殼。 GT3pro:46.6mm和42.9mm,材質是藍寶石玻璃鏡+鈦金屬機身/陶瓷機身+陶瓷後殼二、健康GT4:採用最新的華為Truseen5.5+演算法,結果會更加的精準。 GT3pro:多了ECG心電圖和血管及安

為什麼NameResolutionError(self.host, self, e) from e,怎麼解決 為什麼NameResolutionError(self.host, self, e) from e,怎麼解決 Mar 01, 2024 pm 01:20 PM

報錯的原因NameResolutionError(self.host,self,e)frome是由urllib3函式庫中的例外類型,這個錯誤的原因是DNS解析失敗,也就是說,試圖解析的主機名稱或IP位址無法找到。這可能是由於輸入的URL位址不正確,或DNS伺服器暫時無法使用所導致的。如何解決解決此錯誤的方法可能有以下幾種:檢查輸入的URL地址是否正確,確保它是可訪問的確保DNS伺服器可用,您可以嘗試在命令行中使用"ping"命令來測試DNS伺服器是否可用嘗試使用IP位址而不是主機名稱來存取網站如果是在代理

2 個月不見,人形機器人 Walker S 會摺衣服了 2 個月不見,人形機器人 Walker S 會摺衣服了 Apr 03, 2024 am 08:01 AM

機器之能報道編輯:吳昕國內版的人形機器人+大模型組隊,首次完成疊衣服這類複雜柔性材料的操作任務。隨著融合了OpenAI多模態大模型的Figure01揭開神秘面紗,國內同行的相關進展一直備受關注。就在昨天,國內"人形機器人第一股"優必選發布了人形機器人WalkerS深入融合百度文心大模型後的首個Demo,展示了一些有趣的新功能。現在,得到百度文心大模型能力加持的WalkerS是這個樣子的。和Figure01一樣,WalkerS沒有走動,而是站在桌子後面完成一系列任務。它可以聽從人類的命令,折疊衣物

golang WebSocket與JSON的結合:實現資料傳輸與解析 golang WebSocket與JSON的結合:實現資料傳輸與解析 Dec 17, 2023 pm 03:06 PM

golangWebSocket與JSON的結合:實現資料傳輸和解析在現代的Web開發中,即時資料傳輸變得越來越重要。 WebSocket是一種用於實現雙向通訊的協議,與傳統的HTTP請求-回應模型不同,WebSocket允許伺服器向客戶端主動推送資料。而JSON(JavaScriptObjectNotation)是一種用於資料交換的輕量級格式,它簡潔易讀

html和url的差別是什麼 html和url的差別是什麼 Mar 06, 2024 pm 03:06 PM

區別:1、定義不同,url是是統一資源定位符,而html是超文本標記語言;2、一個html中可以有很多個url,而一個url中只能存在一個html頁面;3、html指的是網頁,而url指的是網站位址。

PHP 數組轉 JSON 的效能最佳化技巧 PHP 數組轉 JSON 的效能最佳化技巧 May 04, 2024 pm 06:15 PM

PHP數組轉JSON的效能最佳化方法包括:使用JSON擴充和json_encode()函數;新增JSON_UNESCAPED_UNICODE選項以避免字元轉義;使用緩衝區提高循環編碼效能;快取JSON編碼結果;考慮使用第三方JSON編碼庫。

MySQL5.7和MySQL8.0的差別是什麼? MySQL5.7和MySQL8.0的差別是什麼? Feb 19, 2024 am 11:21 AM

MySQL5.7和MySQL8.0是兩個不同的MySQL資料庫版本,它們之間有以下一些主要差異:效能改進:MySQL8.0相對於MySQL5.7有一些效能改進。其中包括更好的查詢優化器、更有效率的查詢執行計劃產生、更好的索引演算法和平行查詢等。這些改進可以提高查詢效能和整體系統效能。 JSON支援:MySQL8.0引入了對JSON資料類型的原生支持,包括JSON資料的儲存、查詢和索引。這使得在MySQL中處理和操作JSON資料變得更加方便和有效率。事務特性:MySQL8.0引進了一些新的事務特性,如原子

使用golang中的json.MarshalIndent函數將結構體轉換為格式化的JSON字串 使用golang中的json.MarshalIndent函數將結構體轉換為格式化的JSON字串 Nov 18, 2023 pm 01:59 PM

使用golang中的json.MarshalIndent函數將結構體轉換為格式化的JSON字串在使用Golang編寫程式時,我們經常需要將結構體轉換為JSON字串,在這個過程中,json.MarshalIndent函數可以幫助我們實現格式化的輸出。下面我們將詳細介紹如何使用這個函數,並提供具體的程式碼範例。首先,讓我們建立一個包含一些資料的結構體。以下是示

See all articles