|
@@ -64,17 +64,26 @@ class Base extends Controller//公共控制器
|
|
|
|
|
|
public function searchtop(){//头部关键词搜索
|
|
|
if(request()->isPost()) {
|
|
|
+//在top.html中的form表单下加一个隐藏域 <input type="hidden" name="TOKEN" value="{:session('TOKEN')}"
|
|
|
+ //每次搜索时判断这个存入session的隐藏token值
|
|
|
+ $post_token = input('post.TOKEN');//因为是提交方式是post所以就用post.name(TOKEN)来接收token传过来的值
|
|
|
+ if(!checkToken($post_token)){//如果验证token不一致则提示请勿重复条件页面(token值在每次完成一个搜索时创建一个新的token)
|
|
|
+// $this->error('请不要重复提交页面',url('index/index/index'));
|
|
|
+ echo "<script>alert('请不要重复提交页面!');location.href='".url('index/index/index')."'</script>";
|
|
|
+ }
|
|
|
$keywords = input('keywords');
|
|
|
if($keywords){
|
|
|
$map['title']=['like','%'.$keywords.'%'];
|
|
|
$ke['keywords']=['like','%'.$keywords.'%'];
|
|
|
$search=db('article')->where($map)->whereOr($ke)->select();
|
|
|
if($search){
|
|
|
+ createToken();//搜索成功时创建一个新token
|
|
|
$this->assign(array(
|
|
|
'search'=>$search,
|
|
|
'keywords'=>$keywords,
|
|
|
));
|
|
|
}else{
|
|
|
+ createToken();//搜索失败时创建一个新token
|
|
|
$this->assign(array(
|
|
|
'search'=>null,
|
|
|
'keywords'=>'没有搜索到关键词!',
|