Skip to content

Instantly share code, notes, and snippets.

@meyt
Created September 24, 2018 06:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meyt/7a02e926707e43b5bf02fc2e36d68ff1 to your computer and use it in GitHub Desktop.
Save meyt/7a02e926707e43b5bf02fc2e36d68ff1 to your computer and use it in GitHub Desktop.
<?php
$url = $_GET['r'];
$encoded_url = preg_replace_callback(
'#://([^/]+)/([^?]+)#',
function ($match) {
return
'://' .
$match[1] .
'/' .
join(
'/',
array_map('rawurlencode', explode('/', $match[2]))
);
},
$url
);
if (filter_var($encoded_url, FILTER_VALIDATE_URL)) {
header("Location: {$encoded_url}");
} else {
header("Status: 400 Bad Request");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment