联系官方销售客服
1835022288
028-61286886
解决问题:如何防止别人通过ID来采集网站?
1、创建一个fcaiji的字段,以下是代码
{"name":"防采集","fieldname":"fcaiji","fieldtype":"Text","isedit":"1","ismain":"1","issystem":"0","ismember":"1","issearch":"0","disabled":"0","setting":{"option":{"fieldtype":"CHAR","fieldlength":"4","value":"","width":"","css":""},"validate":{"xss":"1","required":"0","pattern":"","errortips":"","check":"","filter":"user_gl_caiji","tips":"","formattr":""},"is_right":"0"},"displayorder":"0"}
2、在custom.php文件中放出以下代码
function my_cjurl($data) {
$url=$data['fcaiji'].$data['id'].'.html';
return $url;
}
function my_gl_caiji($value, $data = [], $old = []) {
if(empty($value)){
$characters = 'abcdefghijklmnopqrstuvwxyz';
$shuffledCharacters = str_shuffle($characters);
$value = substr($shuffledCharacters, 0, 4);
}
return $value; // 返回的数据一定要是字符串格式!!!
}
3、创建URL规则,这里只有独立模块的
{"id":"4","type":"1","name":"防采集","value":"{\"module\":\"{modname}.html\",\"list\":\"{modname}/{dirname}/\",\"list_page\":\"{modname}/{dirname}/{page}/\",\"show\":\"{modname}/{my_cjurl($data)}\",\"show_page\":\"{modname}/{id}_{page}.html\",\"search\":\"{modname}/sch.html\",\"search_page\":\"{modname}/sch-{param}.html\",\"catjoin\":\"/\"}"}
4、在rewrite.php中用如下规则
"([a-z]+)\/([a-z]+)([0-9]+)\.html" => "index.php?s=$1&c=show&fcaiji=$2&id=$3",
5、在list.html中用上maxlimit=100的参数
6、在hooks.php中用上如下参数
\Phpcmf\Hooks::app_on('appname', 'module_search_data', function($data) {
$page=$_GET['page'];
if($page>5){
XR_C()->goto_404_page(dr_lang('该分页不存在'));
}
});
\Phpcmf\Hooks::app_on('appname', 'module_show', function($data) {
$fcaiji=$_GET['fcaiji'];
if($data['fcaiji']&&$fcaiji!==$data['fcaiji']){
XR_C()->goto_404_page(dr_lang('内容不存在!'));
}
return dr_return_data(1, '', $data);
});
1、创建一个fcaiji的字段,以下是代码
{"name":"防采集","fieldname":"fcaiji","fieldtype":"Text","isedit":"1","ismain":"1","issystem":"0","ismember":"1","issearch":"0","disabled":"0","setting":{"option":{"fieldtype":"CHAR","fieldlength":"4","value":"","width":"","css":""},"validate":{"xss":"1","required":"0","pattern":"","errortips":"","check":"","filter":"user_gl_caiji","tips":"","formattr":""},"is_right":"0"},"displayorder":"0"}