Skip to content

Commit

Permalink
PHP Cors Proxy: Fix warnings, support passing URL via the search path
Browse files Browse the repository at this point in the history
  • Loading branch information
adamziel committed Jul 12, 2024
1 parent 126f0e2 commit 54ca521
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/playground/php-cors-proxy/proxy-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ function get_target_url($server_data=null) {
$targetUrl = substr($targetUrl, strlen($server_data['SCRIPT_NAME']));
}

// Remove the leading slash
if ($targetUrl[0] === '/') {
// Remove the leading slash or question mark, depending on the method
// used to access the script
if (str_starts_with($targetUrl, '/') || str_starts_with($targetUrl, '?')) {
$targetUrl = substr($targetUrl, 1);
}

Expand Down
5 changes: 5 additions & 0 deletions packages/playground/php-cors-proxy/proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ function set_cors_headers() {

// Get the full target URL from the request path
$targetUrl = get_target_url($_SERVER);
if(!$targetUrl) {
http_response_code(400);
echo "Bad Request\n\nNo URL provided";
exit;
}
$resolved = url_validate_and_resolve($targetUrl);
$host = $resolved['host'];
$resolvedIp = $resolved['ip'];
Expand Down

0 comments on commit 54ca521

Please sign in to comment.