mallka/anti-crawl

常规反爬虫安装

安装: 9

依赖: 0

建议者: 0

安全性: 0

星标: 3

关注者: 2

分支: 0

开放问题: 0

语言:JavaScript

类型:yii2-extension

v0.1.1 2020-05-27 05:34 UTC

This package is auto-updated.

Last update: 2024-09-27 15:01:03 UTC


README

特性

  • 拒绝开发工具
  • 如果检测到无头Chrome,运行JavaScript命令。
  • 获取浏览器指纹并发送到某个URL

安装

安装此扩展的首选方式是通过 composer

可以运行

php composer.phar require --prefer-dist mallka/anti-crawl "dev-master"

或者在您的 composer.json 文件的 require 部分添加

"mallka/anti-crawl": "dev-master"

如何使用

###1. 在视图文件中

<?= \mallka\anticrawl\Anti::widget([

        //the url of upload fingerprint,it will not fetch fingerprint if not set
        'uploadFingerUrl'=>Url::to(['/anticrawl/anti-log/create']), 
        
        //run js command if chrome headless detected.default is alert 
        'homelessJsCmd'=>'window.location.href="xxxxx";',  
         
                                   ]);?>

###2. 创建一些收集数据的操作

//sample action ,please create table first.
<?php

	use Yii;
	

	class AntiLogController extends \yii\web\Controller
	{
		public function actionCreate()
		{
			$model = new AntiLog();
			$model->loadDefaultValues();
			$model->ip = Yii::$app->request->getUserIP();
			$model->url =Yii::$app->request->getReferrer();
			$model->finger = Yii::$app->request->post('fingerPrint');
			$model->finger_time = Yii::$app->request->post('executeTime',0);
			$model->finger_detail = Yii::$app->request->post('detail',0);
			$model->create_at=time();
			$model->user_id = Yii::$app->user->getId();
			$model->save();
			return;
		}

	}