如何阻止某人直接访问网页链接?
比如说,我想阻止人们直接访问/blog/index.html。如果他们来自/home/index.html
,他们只能访问该链接我见过JavaScript和PHP的解决方案,但大多数都看起来很乏味。
我有一些HTML和CSS知识,并且对其他语言一无所知,所以有什么能帮到你们提供的,请务必解释一下是吗?
我期待你的回答!谢谢!
答案 0 :(得分:1)
将此添加到<?php if(str_replace("http://www.example.com", "", $_SERVER['HTTP_REFERER']) != "/home/index.html"){echo"Error!";exit;}?>
:
namespace app\components;
use yii;
use yii\web\Controller;
use yii\filters\AccessControl;
class RbacController extends Controller
{
public function RbacRule($modules = false)
{
$rules = false;
if ($modules){
$rules = [
'allow' => true,
'roles' => ['@'],
'matchCallback' => function ($rule, $action) {
$module = Yii::$app->controller->module->id;
$action = Yii::$app->controller->action->id;
$controller = Yii::$app->controller->id;
$route = "/$module/$controller/$action";
$post = Yii::$app->request->post();
if (\Yii::$app->user->can($route)) {
return true;
}
}
];
}else{
$rules = [
'allow' => true,
'roles' => ['@'],
'matchCallback' => function ($rule, $action) {
//$module = Yii::$app->controller->module->id;
$action = Yii::$app->controller->action->id;
$controller = Yii::$app->controller->id;
$route = "/$controller/$action";
$post = Yii::$app->request->post();
if (\Yii::$app->user->can($route)) {
return true;
}
}
];
}
return $rules;
// return true;
}
}
但可能是可操纵的。
答案 1 :(得分:0)
使用Michel的重复问题重定向。谢谢你的回答!
if(!isset($_SERVER['HTTP_REFERER'])){
// redirect them to your desired location
header('location:../index.php');
exit;
}