Add rate limiting requests in article-flat.php
This commit is contained in:
parent
8f30c8e585
commit
7545c5192a
@ -15,6 +15,23 @@
|
||||
if(isset($_REQUEST["first"]))
|
||||
$first=$_REQUEST["first"];
|
||||
|
||||
$logfile=$logdir.'/newsportal.log';
|
||||
if(!isset($_SESSION['starttime'])) {
|
||||
$_SESSION['starttime'] = time();
|
||||
$_SESSION['views'] = 0;
|
||||
}
|
||||
$_SESSION['views']++;
|
||||
|
||||
$rate = ($_SESSION['views'] / (time() - $_SESSION['starttime']));
|
||||
if (($rate > .15) && ($_SESSION['views'] > 5)) {
|
||||
header("HTTP/1.0 429 Too Many Requests");
|
||||
if(!isset($_SESSION['throttled'])) {
|
||||
file_put_contents($logfile, "\n".format_log_date()." ".$config_name." Too many requests from ".$_SERVER['REMOTE_ADDR']." requesting: ".$group, FILE_APPEND);
|
||||
$_SESSION['throttled'] = true;
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if(isset($frames_on) && $frames_on === true) {
|
||||
?>
|
||||
<script>
|
||||
|
@ -1,7 +1,5 @@
|
||||
<?php header("Expires: ".gmdate("D, d M Y H:i:s",time()+7200)." GMT");
|
||||
session_start();
|
||||
$_SESSION['starttime'] = time();
|
||||
$_SESSION['views'] = 0;
|
||||
$_SESSION['isframed'] = 1;
|
||||
|
||||
include "config.inc.php";
|
||||
|
Loading…
x
Reference in New Issue
Block a user