Maison  >  Article  >  développement back-end  >  简略的php代理 Simple PHP Proxy

简略的php代理 Simple PHP Proxy

WBOY
WBOYoriginal
2016-06-13 11:57:182474parcourir

简单的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:xml"/>' )			  		.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>Request URL</h3><p id="request">N/A, click Submit!</p><h3>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>...</script>
Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn