Php proxy for http

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

A PHP proxy script with https and post support

jenssegers/php-proxy

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

added example block to handle bad responses

Git stats

Files

Failed to load latest commit information.

README.md

This is a HTTP/HTTPS proxy script that forwards requests to a different server and returns the response. The Proxy class uses PSR7 request/response objects as input/output, and uses Guzzle to do the actual HTTP request.

composer require jenssegers/proxy 

The following example creates a request object, based on the current browser request, and forwards it to example.com . The RemoveEncodingFilter removes the encoding headers from the original response so that the current webserver can set these correctly.

use Proxy\Proxy; use Proxy\Adapter\Guzzle\GuzzleAdapter; use Proxy\Filter\RemoveEncodingFilter; use Laminas\Diactoros\ServerRequestFactory; // Create a PSR7 request based on the current browser request. $request = ServerRequestFactory::fromGlobals(); // Create a guzzle client $guzzle = new GuzzleHttp\Client(); // Create the proxy instance $proxy = new Proxy(new GuzzleAdapter($guzzle)); // Add a response filter that removes the encoding headers. $proxy->filter(new RemoveEncodingFilter()); try < // Forward the request and get the response. $response = $proxy->forward($request)->to('http://example.com'); // Output response to the browser. (new Laminas\HttpHandlerRunner\Emitter\SapiEmitter)->emit($response); > catch(\GuzzleHttp\Exception\BadResponseException $e) < // Correct way to handle bad responses (new Laminas\HttpHandlerRunner\Emitter\SapiEmitter)->emit($e->getResponse()); >

You can apply filters to the requests and responses using the middleware strategy:

$response = $proxy ->forward($request) ->filter(function ($request, $response, $next) < // Manipulate the request object. $request = $request->withHeader('User-Agent', 'FishBot/1.0'); // Call the next item in the middleware. $response = $next($request, $response); // Manipulate the response object. $response = $response->withHeader('X-Proxy-Foo', 'Bar'); return $response; >) ->to('http://example.com');

About

A PHP proxy script with https and post support

Источник

codedokode / proxy.php

This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters

/**
* Простой прокси-сервер на PHP для изучения и модификации данных,
* передаваемых между браузером и сторонним сервером.
*
* Запуск:
*
* указать URL сайта в $base
* php -S 127.0.0.1:9001 proxy.php
*
* После этого в браузере можно открывать http://127.0.0.1:9001/
* и все запросы пойдут через прокси на указанный в $base адрес.
*/
// Для вывода данных в консоль
$ stderr = fopen( ‘php://stderr’ , ‘w’ );
$ url = $ _SERVER [ ‘REQUEST_URI’ ];
$ path = parse_url( $ url , PHP_URL_PATH );
$ query = parse_url( $ url , PHP_URL_QUERY );
$ newPath = ltrim( $ path , ‘/’ );
if ( $ query )
$ newPath .= ‘?’ . $ query ;
>
$ base = ‘https://someapprentice.github.io/maintaskforlayout/’ ;
$ proxyUrl = $ base . $ newPath ;
// $context = stream_context_create();
$ contents = @file_get_contents( $ proxyUrl /* , false, $context */ );
// Получаем заголовки ответа из глобальной переменной (PHP!)
$ headers = $ http_response_header ;
$ firstLine = $ headers [ 0 ];
if ( $ contents === false )
fwrite( $ stderr , » Request failed: $ proxyUrl — $ firstLine \n»);
header(» HTTP/1.1 503 Proxy error «);
die(» Proxy failed to get contents at $ proxyUrl «);
>
fwrite( $ stderr , » $ proxyUrl — OK: $ firstLine \n»);
$ allowedHeaders = » !^(http/1.1|server:|content-type:|last-modified|access-control-allow-origin|Content-Length:|Accept-Ranges:|Date:|Via:|Connection:|X-|age|cache-control|vary)!i «;
// Прокидываем разрешенные заголовки
foreach ( $ headers as $ header )
if (preg_match( $ allowedHeaders , $ header ))
fwrite( $ stderr , » + $ header \n»);
header( $ header );
> else
fwrite( $ stderr , » — $ header \n»);
>
>
echo $ contents ;

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

PHP based web proxy. Initially developed by whitefyre

License

PHProxy/phproxy

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

PHProxy is a web HTTP proxy written in PHP. It is designed to bypass proxy restrictions through a web interface very similar to the popular CGIProxy. The only thing that PHProxy needs is a web server with PHP installed (see Requirements below). Be aware though, that the sever has to be able to access those resources to deliver them to you.

Originaly developed in SourceForge during 2002-2007 and then abandoned. This project needs to live and it’s development is continued here.

This source code is released under the GPL. A copy of the license is provided in this package in the filename LICENSE.md .

  • PHP version > 5
  • safe_mode turned off or at least having the fsockopen() function not disabled
  • OpenSSL for support for secure connections (https)
  • Zlib for output compression
  • file_uploads turned On for HTTP file uploads.

Copy the files of the repository in your public web server folder or to a directory of your liking (prefrebly in its own directory).

cd /var/www/html/ git clone https://github.com/PHProxy/phproxy.git 

You simply supply a URL to the form and click Browse. The script then accesses that URL, and if it has any HTML contents, it modifies any URLs so that they point back to the script. Of course, there is more to it than this, but if you would like to know more in detail, view the source code.

PHP is restrictive by nature, and as such, some problems arise that would have not if this project were otherwise coded in another programming language. The first example of this is the dots in incoming variable names from POST and GET methods. In a normal programming language, this wouldn’t be a problem as these variables could be accessed normally as they are supplied, with dots included. In PHP, however, dots in GET, POST, and COOKIE variable names are magically transformed into underscores because of register_globals . Things like Yahoo! Mail which has dots in variable names will not work. There’s no easy way around this, but luckily, I have provided the solutions right here:

  1. I’ve already taken care of cookies by manually transforming the underscores manually into dots when needed.
  2. For GET variables, this shouldn’t be a huge problem since the URLs are URL-encoded into the url_var_name. The only time this should be an issue is when a GET form uses dots in input names, and this could be recitified by using $_SERVER[‘QUERY_STRING’], and parsing that variable. But this, luckily, doesn’t happen too often.
  3. As for POST data, one solution is to use $HTTP_RAW_POST_DATA. But then, this variable might not be available in certain PHP configurations, and it would need further parsing, and it still doesn’t account for uploaded FILES. This is extremely impractical and ugly.

The best thing you could do if you have enough control over your Web server and can compile custom builds of PHP is to delete a single line in a PHP source code file called «php_variables.c» located in the «main» directory. The function in question is called «php_register_variable_ex». I’ve only checked this with PHP v4.4.4 and the exact line to delete is 117th line which basically consists of this:

Now just compile and install PHP and everything should be fine. Just make sure that you have register_globals off or something might get messed up.

Another problem facing many Web proxies is support for JavaScript. The best thing you could do right now is to have the JavaScript disabled on your browsing options as most sites degrade gracefully, such as Gmail.

A third limitation for Web proxies is content accessed from within proxied Flash and Java applications and such. Since the proxy script doesn’t have access to the source code of these applications, the links which they may decide to stream or access will not be proxified. There’s no easy solution for this right now.

PHProxy also doesn’t support FTP. This may or may not be introduced in future releases, but there are no current plans for FTP support.

Источник

Читайте также:  Brackets Junior
Оцените статью