Inhaltsverzeichnis
Request URL
Simple PHP Proxy response
Heim Backend-Entwicklung PHP-Tutorial 简略的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>
Nach dem Login kopieren

?

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;  }
Nach dem Login kopieren

?

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

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

?

?

?

Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn

Heiße KI -Werkzeuge

Undresser.AI Undress

Undresser.AI Undress

KI-gestützte App zum Erstellen realistischer Aktfotos

AI Clothes Remover

AI Clothes Remover

Online-KI-Tool zum Entfernen von Kleidung aus Fotos.

Undress AI Tool

Undress AI Tool

Ausziehbilder kostenlos

Clothoff.io

Clothoff.io

KI-Kleiderentferner

AI Hentai Generator

AI Hentai Generator

Erstellen Sie kostenlos Ai Hentai.

Heißer Artikel

R.E.P.O. Energiekristalle erklärten und was sie tun (gelber Kristall)
3 Wochen vor By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Beste grafische Einstellungen
3 Wochen vor By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. So reparieren Sie Audio, wenn Sie niemanden hören können
3 Wochen vor By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: Wie man alles in Myrise freischaltet
4 Wochen vor By 尊渡假赌尊渡假赌尊渡假赌

Heiße Werkzeuge

Notepad++7.3.1

Notepad++7.3.1

Einfach zu bedienender und kostenloser Code-Editor

SublimeText3 chinesische Version

SublimeText3 chinesische Version

Chinesische Version, sehr einfach zu bedienen

Senden Sie Studio 13.0.1

Senden Sie Studio 13.0.1

Leistungsstarke integrierte PHP-Entwicklungsumgebung

Dreamweaver CS6

Dreamweaver CS6

Visuelle Webentwicklungstools

SublimeText3 Mac-Version

SublimeText3 Mac-Version

Codebearbeitungssoftware auf Gottesniveau (SublimeText3)

Was sind die Unterschiede zwischen Huawei GT3 Pro und GT4? Was sind die Unterschiede zwischen Huawei GT3 Pro und GT4? Dec 29, 2023 pm 02:27 PM

Viele Benutzer werden sich bei der Auswahl von Smartwatches für die Marke Huawei entscheiden. Viele Benutzer sind neugierig auf den Unterschied zwischen Huawei GT3pro und GT4. Was sind die Unterschiede zwischen Huawei GT3pro und GT4? 1. Aussehen GT4: 46 mm und 41 mm, das Material ist Glasspiegel + Edelstahlgehäuse + hochauflösende Faserrückschale. GT3pro: 46,6 mm und 42,9 mm, das Material ist Saphirglas + Titangehäuse/Keramikgehäuse + Keramikrückschale 2. Gesundes GT4: Mit dem neuesten Huawei Truseen5.5+-Algorithmus werden die Ergebnisse genauer. GT3pro: EKG-Elektrokardiogramm sowie Blutgefäß und Sicherheit hinzugefügt

Warum NameResolutionError(self.host, self, e) von e und wie man es löst Warum NameResolutionError(self.host, self, e) von e und wie man es löst Mar 01, 2024 pm 01:20 PM

Der Grund für den Fehler ist NameResolutionError(self.host,self,e)frome, ein Ausnahmetyp in der urllib3-Bibliothek. Der Grund für diesen Fehler ist, dass die DNS-Auflösung fehlgeschlagen ist, d. h. der Hostname oder die IP-Adresse Der Lösungsversuch konnte nicht gefunden werden. Dies kann daran liegen, dass die eingegebene URL-Adresse falsch ist oder der DNS-Server vorübergehend nicht verfügbar ist. So beheben Sie diesen Fehler Es gibt möglicherweise mehrere Möglichkeiten, diesen Fehler zu beheben: Überprüfen Sie, ob die eingegebene URL-Adresse korrekt ist und stellen Sie sicher, dass sie zugänglich ist. Stellen Sie sicher, dass der DNS-Server verfügbar ist. Sie können es mit dem Befehl „ping“ in der Befehlszeile versuchen Um zu testen, ob der DNS-Server verfügbar ist, versuchen Sie, über die IP-Adresse statt über den Hostnamen auf die Website zuzugreifen, wenn Sie sich hinter einem Proxy befinden

Nach 2 Monaten kann der humanoide Roboter Walker S Kleidung falten Nach 2 Monaten kann der humanoide Roboter Walker S Kleidung falten Apr 03, 2024 am 08:01 AM

Herausgeber des Machine Power Report: Wu Xin Die heimische Version des humanoiden Roboters + eines großen Modellteams hat zum ersten Mal die Betriebsaufgabe komplexer flexibler Materialien wie das Falten von Kleidung abgeschlossen. Mit der Enthüllung von Figure01, das das multimodale große Modell von OpenAI integriert, haben die damit verbundenen Fortschritte inländischer Kollegen Aufmerksamkeit erregt. Erst gestern veröffentlichte UBTECH, Chinas „größter Bestand an humanoiden Robotern“, die erste Demo des humanoiden Roboters WalkerS, der tief in das große Modell von Baidu Wenxin integriert ist und einige interessante neue Funktionen aufweist. Jetzt sieht WalkerS, gesegnet mit Baidu Wenxins großen Modellfähigkeiten, so aus. Wie Figure01 bewegt sich WalkerS nicht umher, sondern steht hinter einem Schreibtisch, um eine Reihe von Aufgaben zu erledigen. Es kann menschlichen Befehlen folgen und Kleidung falten

Kombination von Golang WebSocket und JSON: Realisierung der Datenübertragung und -analyse Kombination von Golang WebSocket und JSON: Realisierung der Datenübertragung und -analyse Dec 17, 2023 pm 03:06 PM

Die Kombination von golangWebSocket und JSON: Datenübertragung und Parsing realisieren In der modernen Webentwicklung wird die Datenübertragung in Echtzeit immer wichtiger. WebSocket ist ein Protokoll, das zur bidirektionalen Kommunikation verwendet wird. Im Gegensatz zum herkömmlichen HTTP-Anfrage-Antwort-Modell ermöglicht WebSocket dem Server, Daten aktiv an den Client zu übertragen. JSON (JavaScriptObjectNotation) ist ein leichtes Format für den Datenaustausch, das prägnant und leicht lesbar ist.

Was ist der Unterschied zwischen HTML und URL? Was ist der Unterschied zwischen HTML und URL? Mar 06, 2024 pm 03:06 PM

Unterschiede: 1. Unterschiedliche Definitionen, URL ist ein einheitlicher Ressourcen-Locator und HTML ist eine Hypertext-Markup-Sprache. 2. Es kann viele URLs in einer HTML-Seite geben, aber nur eine HTML-Seite kann in einer URL vorhanden sein eine Webseite, und URL bezieht sich auf die Website-Adresse.

Was ist der Unterschied zwischen MySQL5.7 und MySQL8.0? Was ist der Unterschied zwischen MySQL5.7 und MySQL8.0? Feb 19, 2024 am 11:21 AM

MySQL5.7 und MySQL8.0 sind zwei verschiedene MySQL-Datenbankversionen. Es gibt einige Hauptunterschiede zwischen ihnen: Leistungsverbesserungen: MySQL8.0 weist im Vergleich zu MySQL5.7 einige Leistungsverbesserungen auf. Dazu gehören bessere Abfrageoptimierer, eine effizientere Erstellung von Abfrageausführungsplänen, bessere Indizierungsalgorithmen und parallele Abfragen usw. Diese Verbesserungen können die Abfrageleistung und die Gesamtsystemleistung verbessern. JSON-Unterstützung: MySQL 8.0 führt native Unterstützung für den JSON-Datentyp ein, einschließlich Speicherung, Abfrage und Indizierung von JSON-Daten. Dies macht die Verarbeitung und Bearbeitung von JSON-Daten in MySQL bequemer und effizienter. Transaktionsfunktionen: MySQL8.0 führt einige neue Transaktionsfunktionen ein, z. B. atomic

Tipps zur Leistungsoptimierung für die Konvertierung von PHP-Arrays in JSON Tipps zur Leistungsoptimierung für die Konvertierung von PHP-Arrays in JSON May 04, 2024 pm 06:15 PM

Zu den Leistungsoptimierungsmethoden für die Konvertierung von PHP-Arrays in JSON gehören: Verwendung von JSON-Erweiterungen und der Funktion json_encode(); Verwendung von Puffern zur Verbesserung der Leistung der Schleifencodierung; JSON-Codierungsbibliothek.

Verwenden Sie die Funktion json.MarshalIndent in Golang, um die Struktur in einen formatierten JSON-String zu konvertieren Verwenden Sie die Funktion json.MarshalIndent in Golang, um die Struktur in einen formatierten JSON-String zu konvertieren Nov 18, 2023 pm 01:59 PM

Verwenden Sie die Funktion json.MarshalIndent in Golang, um die Struktur in einen formatierten JSON-String zu konvertieren. Bei diesem Prozess kann uns die Funktion json.MarshalIndent helfen formatierte Ausgabe. Im Folgenden erläutern wir detailliert die Verwendung dieser Funktion und stellen konkrete Codebeispiele bereit. Erstellen wir zunächst eine Struktur mit einigen Daten. Das Folgende ist ein Hinweis

See all articles