{"id":15046811,"url":"https://github.com/zounar/php-proxy","last_synced_at":"2025-04-05T02:08:56.353Z","repository":{"id":43029878,"uuid":"72301265","full_name":"zounar/php-proxy","owner":"zounar","description":"Simple PHP proxy script","archived":false,"fork":false,"pushed_at":"2023-04-08T21:54:38.000Z","size":25,"stargazers_count":173,"open_issues_count":3,"forks_count":91,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-03-29T01:09:52.568Z","etag":null,"topics":["curl","curlphp","http","http-proxy","php","php-proxy","proxy","proxy-script"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zounar.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-10-29T18:07:06.000Z","updated_at":"2025-03-26T19:19:25.000Z","dependencies_parsed_at":"2025-02-01T22:10:55.649Z","dependency_job_id":"c2a56e6e-a90d-4c60-9ae6-73bf402269f5","html_url":"https://github.com/zounar/php-proxy","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zounar%2Fphp-proxy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zounar%2Fphp-proxy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zounar%2Fphp-proxy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zounar%2Fphp-proxy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zounar","download_url":"https://codeload.github.com/zounar/php-proxy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247276164,"owners_count":20912288,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["curl","curlphp","http","http-proxy","php","php-proxy","proxy","proxy-script"],"created_at":"2024-09-24T20:53:36.579Z","updated_at":"2025-04-05T02:08:56.334Z","avatar_url":"https://github.com/zounar.png","language":"PHP","readme":"# Simple PHP Proxy\n\nThis proxy script allows you to forward all HTTP/HTTPS requests to another server. Works for all common request types \nincluding GET, POST requests with files, PATCH and PUT requests. It has minimal set of requirements \n(PHP \u003e=5.6, libcurl, gzip) which are available even on the smallest free hostings and has its own simple authorization \nand cookie support.\n\n## How to use\n* Copy the [Proxy.php](Proxy.php) script to publicly-accessible folder of a PHP web server (the script is standalone and has no PHP dependencies)\n* Make a cURL request targeting this script\n* Add **Proxy-Auth** header with auth key [found here](https://github.com/zounar/php-proxy/blob/master/Proxy.php#L40)\n* Add **Proxy-Target-URL** header with URL to be requested by the proxy\n* (Optional) Add **Proxy-Debug** header for debug mode\n\nIn order to protect using proxy by unauthorized users, consider changing `Proxy-Auth` token in [proxy source file](https://github.com/zounar/php-proxy/blob/master/Proxy.php#L40) and in all your requests.\n\n## How to use (via composer)\nThis might be useful when you want to redirect requests coming into your app. \n\n* Run `composer require zounar/php-proxy`\n* Add `Proxy::run();` line to where you want to execute it (usually into a controller action)\n  * In this example, the script is in `AppController` - `actionProxy`:\n    ```\n    use Zounar\\PHPProxy\\Proxy;\n    \n    class AppController extends Controller {\n\n        public function actionProxy() {\n            Proxy::$AUTH_KEY = '\u003cyour-new-key\u003e';\n            // Do your custom logic before running proxy\n            $responseCode = Proxy::run();\n            // Do your custom logic after running proxy\n            // You can utilize HTTP response code returned from the run() method\n        }\n    }\n    ```\n* Make a cURL request to your web\n  * In the example, it would be `http://your-web.com/app/proxy`\n* Add **Proxy-Auth** header with auth key [found here](https://github.com/zounar/php-proxy/blob/master/Proxy.php#L40)\n* Add **Proxy-Target-URL** header with URL to be requested by the proxy\n* (Optional) Add **Proxy-Debug** header for debug mode\n\nIn order to protect using proxy by unauthorized users, consider changing `Proxy-Auth` token by calling\n`Proxy::$AUTH_KEY = '\u003cyour-new-key\u003e';` before `Proxy::run()`. Then change the token in all your requests.\n\n## Usage example\nFollowing example shows how to execute GET request to https://www.github.com. Proxy script is at http://www.foo.bar/Proxy.php. All proxy settings are kept default, the response is automatically echoed.\n\n```php\n$request = curl_init('http://www.foo.bar/Proxy.php');\n\ncurl_setopt($request, CURLOPT_HTTPHEADER, array(\n    'Proxy-Auth: Bj5pnZEX6DkcG6Nz6AjDUT1bvcGRVhRaXDuKDX9CjsEs2',\n    'Proxy-Target-URL: https://www.github.com'\n));\n\ncurl_exec($request);\n```\n\n## Debugging\nIn order to show some debug info from the proxy, add `Proxy-Debug: 1` header into the request. This will show debug info in plain-text containing request headers, response headers and response body.\n\n```php\n$request = curl_init('http://www.foo.bar/Proxy.php');\n\ncurl_setopt($request, CURLOPT_HTTPHEADER, array(\n    'Proxy-Auth: Bj5pnZEX6DkcG6Nz6AjDUT1bvcGRVhRaXDuKDX9CjsEs2',\n    'Proxy-Target-URL: https://www.github.com',\n    'Proxy-Debug: 1'\n));\n\ncurl_exec($request);\n```\n\n## Specifying User-Agent\nSome sites may return different content for different user agents. In such case add `User-Agent` header to cURL request, it will be automatically passed to the request for target site. In this case it's Firefox 70 for Ubuntu.\n\n```php\n$request = curl_init('http://www.foo.bar/Proxy.php');\n\ncurl_setopt($request, CURLOPT_HTTPHEADER, array(\n    'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:70.0) Gecko/20100101 Firefox/70.0',\n    'Proxy-Auth: Bj5pnZEX6DkcG6Nz6AjDUT1bvcGRVhRaXDuKDX9CjsEs2',\n    'Proxy-Target-URL: https://www.github.com'\n));\n\ncurl_exec($request);\n```\n\n## Error 301 Moved permanently\nIt might occur that there's a redirection when calling the proxy (not the target site), eg. during `http -\u003e https` redirection. You can either modify/fix the proxy URL (which is recommended), or add `CURLOPT_FOLLOWLOCATION` option before `curl_exec`.\n\n```php\n$request = curl_init('http://www.foo.bar/Proxy.php');\n\ncurl_setopt($request, CURLOPT_FOLLOWLOCATION, true );\ncurl_setopt($request, CURLOPT_HTTPHEADER, array(\n    'Proxy-Auth: Bj5pnZEX6DkcG6Nz6AjDUT1bvcGRVhRaXDuKDX9CjsEs2',\n    'Proxy-Target-URL: https://www.github.com'\n));\n\ncurl_exec($request);\n```\n\n## Save response into variable\nThe default cURL behavior is to echo the response of `curl_exec`. In order to save response into variable, all you have to do is to add `CURLOPT_RETURNTRANSFER` cURL option.\n\n```php\n$request = curl_init('http://www.foo.bar/Proxy.php');\n\ncurl_setopt($request, CURLOPT_RETURNTRANSFER, true);\ncurl_setopt($request, CURLOPT_HTTPHEADER, array(\n    'Proxy-Auth: Bj5pnZEX6DkcG6Nz6AjDUT1bvcGRVhRaXDuKDX9CjsEs2',\n    'Proxy-Target-URL: https://www.github.com'\n));\n\n$response = curl_exec($request);\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzounar%2Fphp-proxy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzounar%2Fphp-proxy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzounar%2Fphp-proxy/lists"}