A simple PHP-based CORS proxy server that allows you to bypass CORS restrictions by forwarding HTTP requests to a target URL and adding necessary CORS headers to the response.
-
clean_url($url):- Purpose: This function cleans and validates the provided URL.
- Description: It trims the URL and checks if it’s a valid URL using
filter_varwithFILTER_VALIDATE_URL. If the URL is invalid, it returnsfalse.
-
CORS Headers:
- Purpose: Automatically adds CORS headers to the response.
- Description: The script sends the header
Access-Control-Allow-Origin: *, allowing cross-origin requests. It also includes theX-Forwarded-Forheader to pass the client's IP address.
-
cURL Request:
- Purpose: The script uses cURL to forward the request to the target URL and fetch the response.
- Description: It initializes a cURL session, sets various options (like URL, return transfer, and follow location), and executes the request to fetch the response from the target URL. If any cURL error occurs, it is displayed.
-
Response Handling:
- Purpose: The response from the cURL request is returned to the client.
- Description: After cURL fetches the response, the content is sent back to the client, along with the CORS headers, effectively bypassing any CORS restrictions on the target server.
- The script expects a URL as part of the request path (e.g.,
corsproxy.php/target-url). - It then validates and cleans the target URL, forwards the request to that URL, and returns the response with appropriate CORS headers.
This project is licensed under the MIT License. See the LICENSE file for more details.