新链接的格式:http://example.com/videos?name=video01
调用此函数向控制器或http://example.com/videos/index.php
的顶部:
function redirect()
{
if (!empty($_GET['name'])) {
// sanitize & validate $_GET['name']
// Remove anything which isn't a word, whitespace, number
// or any of the following caracters -_~,;[]().
// If you don't need to handle multi-byte characters
// you can use preg_replace rather than mb_ereg_replace
$file = mb_ereg_replace("([^\w\s\d\-_~,;\[\]\(\).])", '', $_GET['name']);
// Remove any runs of periods
$file = mb_ereg_replace("([\.]{2,})", '', $file);
$valid = file_exists('pathToFiles/' . $file);
if ($valid) {
$url = '/videos#' . $file;
} else {
$url = '/your404page.php';
}
header("Location: $url");
}
}
消毒从这个高度排名回答片段:https://stackoverflow.com/a/2021729/1296209
顺便说一句,我试图与位.ly的API并没有工作。 – kinduff