|
| 1 | +# [PHP] Ultra Small Proxy |
| 2 | +### PHP 5.6+ / PHP 7 |
| 3 | + |
| 4 | +Current version: 1.1 |
| 5 | + |
| 6 | +Ultra Small Proxy is a light-weight proxy written in PHP. |
| 7 | + |
| 8 | +## Features: |
| 9 | + |
| 10 | +- Proxy server written in PHP |
| 11 | +- Easy usage and integration |
| 12 | +- Standalone and external usage (it is only one PHP class) |
| 13 | +- Simple and light-weight |
| 14 | +- Sessions support |
| 15 | +- Sending and receiving cookies |
| 16 | +- GET and POST connections |
| 17 | +- Forms submiting support |
| 18 | +- POST variables redirecting |
| 19 | +- Toolbar with address bar and connection debugger |
| 20 | +- URLs rewriting at runtime (links, images, css, javascript, etc.) |
| 21 | +- 2 different methods for URLs rewriting: Regex (via preg_replace) and DOM XML (via libxml & DOMDocument) |
| 22 | +- PHP 5 and PHP 7 supported |
| 23 | + |
| 24 | + |
| 25 | +## Usage example: |
| 26 | +``` |
| 27 | +<?php |
| 28 | +
|
| 29 | +/* include class */ |
| 30 | +include __DIR__.'/UltraSmallProxy.php'; |
| 31 | +
|
| 32 | +/* instantiate proxy */ |
| 33 | +$proxy = new UltraSmallProxy(); |
| 34 | +
|
| 35 | +/* specify start page and load it! */ |
| 36 | +$output = $proxy->load('https://github.com'); |
| 37 | +
|
| 38 | +/* render output */ |
| 39 | +echo $output; |
| 40 | +
|
| 41 | +``` |
| 42 | +Make sure to have write permissions to `./cookies` directory. |
| 43 | + |
| 44 | +## Screenshot: |
| 45 | + |
| 46 | + |
| 47 | + |
| 48 | + |
| 49 | +Open `loopback.php`if you want to test proxy features like sessions support, POST vars redirecting, form submiting and more, e.g.: |
| 50 | +``` |
| 51 | +<?php |
| 52 | +$output = $proxy->load('http://localhost/loopback.php'); |
| 53 | +``` |
| 54 | + |
| 55 | +## Repository contents: |
| 56 | + |
| 57 | +- `UltraSmallProxy.php` - proxy class |
| 58 | +- `index.php` - usage example |
| 59 | +- `loopback.php` - loopback for test features like session support, form vars sending, and cookies redirecting |
| 60 | + |
| 61 | + |
| 62 | +## Options: |
| 63 | + |
| 64 | +``` |
| 65 | +$proxy = new UltraSmallProxy($init = true, $rewriteMode = 'regex', $attachToolbar = true); |
| 66 | +``` |
| 67 | +`$init` - autostarts listening for URLs in QUERY STRING, set to `false` if you want to disable this feature, default: `true` |
| 68 | + |
| 69 | +`$rewriteMode` - method used to URLs rewriting, possible values: `regex` (rewriting by regular expressions), `dom` (rewriting by DOM XML), `null` (disable rewriting), default: `regex` |
| 70 | + |
| 71 | +`$attachToolbar` - appends toolbar DIV, CSS and JS to output when `true`, set to `false` if you want to disable this feature, default: `true` |
| 72 | + |
| 73 | + |
| 74 | +``` |
| 75 | +$output = $proxy->load('https://github.com', $force = false); |
| 76 | +``` |
| 77 | +`$force` - if set to `false` then URLs given from QUERY STRING are always overwriting URLs passed here, set to `true` if you want to reverse this behaviour, default: `false` |
| 78 | + |
| 79 | + |
| 80 | +## Public methods: |
| 81 | + |
| 82 | +Before page load: |
| 83 | + |
| 84 | +`$proxy->setUserAgent($agent)` - sets custom User Agent, defaul: `Mozilla/4.0 (compatible;)` |
| 85 | + |
| 86 | +`$proxy->setRewriteMode($rewriteMode)` - sets URLs rewrite mode: `regex`|`dom`|`null` |
| 87 | + |
| 88 | +`$proxy->setMethod($method)` - sets request method: `GET`|`POST` |
| 89 | + |
| 90 | +`$proxy->setCookiesDir($path)` - sets directory for proxied cookies storage, default: `cookies` |
| 91 | + |
| 92 | + |
| 93 | + |
| 94 | +After page load: |
| 95 | + |
| 96 | +`$siteCookies = $proxy->getSiteCookies()` - returns cookies[] received from proxied site |
| 97 | + |
| 98 | +`$localCookies = $proxy->getLocalCookies()` - returns cookies[] stored localy and sended to proxied site |
| 99 | + |
| 100 | +`$status = $proxy->getStatus()` - returns connection status[] |
| 101 | + |
| 102 | +`$sid = $proxy->getSid()` - returns proxied PHPSESSID if exists |
| 103 | + |
| 104 | +`$isError = $proxy->isError()` - returns `true` if any error occured, `false` if not |
| 105 | + |
| 106 | +`$isCurlError = $proxy->isCurlError()` - returns `true` if curl error occured, `false` if not |
| 107 | + |
| 108 | +`$errorMessages = $proxy->getErrorMessages()` - returns error messages[] if occured |
| 109 | + |
| 110 | + |
| 111 | + |
| 112 | +Other: |
| 113 | + |
| 114 | +`$parsed = $proxy->parse($html)` - parse/rewrite URLs in custom html content with selected `$rewriteMode` |
| 115 | + |
| 116 | + |
| 117 | + |
| 118 | + |
| 119 | +### Ultra Small Proxy is free to use but if you liked then you can donate project via BTC: |
| 120 | + |
| 121 | +**1LK9tDPBuBFXCKUThFWXNvdcdJ4gzx1Diz** |
| 122 | + |
| 123 | +or by PayPal: |
| 124 | + **[https://www.paypal.me/szczyglinski](https://www.paypal.me/szczyglinski)** |
| 125 | + |
| 126 | + |
| 127 | +Enjoy! |
| 128 | + |
| 129 | + |
| 130 | +MIT License | 2020 Marcin 'szczyglis' Szczygliński |
| 131 | + |
| 132 | +https://github.com/szczyglis-dev/php-ultra-small-proxy |
| 133 | + |
| 134 | +Contact: szczyglis ("12 Monkeys" movie is awesome) protonmail.com |
0 commit comments