mirror of
https://gh.wpcy.net/https://github.com/webguyio/dam-spam.git
synced 2026-05-25 03:03:57 +08:00
43 lines
No EOL
1.4 KiB
PHP
43 lines
No EOL
1.4 KiB
PHP
<?php
|
|
|
|
if ( !defined( 'ABSPATH' ) ) {
|
|
status_header( 404 );
|
|
exit;
|
|
}
|
|
|
|
class dam_spam_check_referer extends dam_spam_module {
|
|
public function process( $ip, &$stats = array(), &$options = array(), &$post = array() ) {
|
|
$this->searchname = 'HTTP_REFERER check';
|
|
if ( !isset( $_SERVER['REQUEST_METHOD'] ) || sanitize_text_field( wp_unslash( $_SERVER['REQUEST_METHOD'] ) ) !== 'POST' ) {
|
|
return false;
|
|
}
|
|
$ref = '';
|
|
if ( array_key_exists( 'HTTP_REFERER', $_SERVER ) ) {
|
|
$ref = isset( $_SERVER['HTTP_REFERER'] ) ? sanitize_text_field( wp_unslash( $_SERVER['HTTP_REFERER'] ) ) : '';
|
|
}
|
|
$ua = '';
|
|
if ( array_key_exists( 'HTTP_USER_AGENT', $_SERVER ) ) {
|
|
$ua = isset( $_SERVER['HTTP_USER_AGENT'] ) ? sanitize_text_field( wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) ) : '';
|
|
}
|
|
$a = array( false, '' );
|
|
if ( strpos( strtolower( $ua ), 'iphone' ) === false && strpos( strtolower( $ua ), 'ipad' ) === false ) {
|
|
return false;
|
|
}
|
|
$host = isset( $_SERVER['HTTP_HOST'] ) ? sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) ) : '';
|
|
if ( empty( $ref ) ) {
|
|
return esc_html__( 'Missing HTTP_REFERER', 'dam-spam' );
|
|
}
|
|
if ( empty( $host ) ) {
|
|
return esc_html__( 'Missing HTTP_HOST', 'dam-spam' );
|
|
}
|
|
if ( empty( $ref ) ) {
|
|
return false;
|
|
}
|
|
if ( strpos( strtolower( $ref ), strtolower( $host ) ) === false ) {
|
|
return esc_html__( 'Invalid HTTP_REFERER', 'dam-spam' );
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
|
|
?>
|