了解为此,您需要一个相当复杂的路由部分逻辑。建议使用将为您处理自定义路由的 PHP 框架来实现这一点,例如FuelPHP或Laravel 4。
例如,在 Laravel 4 中,你可以定义这样的路由:
Route::get('streams/{token}', 'StreamController@showStream');
然后,您将定义一个app/controllers/StreamController.php具有如下操作的控制器:
[..]
class StreamController extends BaseController {
[..]
public function showStream($token) {
$ip = Request::server('REMOTE_ADDR');
$url = Request::url();
// do some hashing on the user's IP and $token (and maybe a timestamp)
// compare it with the $url the user tried to view - not going to write that code for you :)
if($allowed) {
return View::make('your.defined.view.with.stream');
} else {
return Redirect::to('/');
}
[..]
}
这只是一个粗略的例子,实际的代码需要更多的努力。但我只是想给你指出正确的方向。我想保持这个答案相当简短。你的目标当然可以通过一百万种不同的方式来实现,使用无数种不同的框架,但这就是我使用 Laravel 4 实现它的方式。