mallka/anti-crawl

常规反爬虫安装

Installs: 7

Dependents: 0

Suggesters: 0

Security: 0

Stars: 3

Watchers: 2

Forks: 0

Open Issues: 0

Language:JavaScript

Type:yii2-extension

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

This package is auto-updated.

Last update: 2024-03-27 13:58:58 UTC


README

Feature

  • reject dev tool
  • run a javascript command if chome headless deteactd.
  • get browser fingerprint and post to SOME URL

Install

The preferred way to install this extension is through composer.

Either run

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

or add

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

to the require section of your composer.json file.

How to use

###1. In view file:

<?= \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.Create some action for collect data

//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;
		}

	}