Rate Limiting the Post Request

If you want to rate limit the post request made on script. You can edit below 2 files and limit the number of request made on each post request that happens to your site. 

Let's start with "File Uploading" 

if you want to rate limit the request made for uploading files, you can edit "onefolder/app/Http/Controllers/ImgurController.php" file and add below line at line no. 30 

public function __construct() {
	$this->middleware('throttle:2,2')->only('uploadFiles');
}

Above code will limit "2" Request per 2 minute. If you want to set higher value for request for example 5 request per 2 minute, than you can change `throttle:5,2` and if you want to change minute from 2 to 10, you can do that with `throttle:2,10`.

Now, Let's limit the post request made on each post request made on your site for example "voting", "commenting", "liking" , "publishing" etc.,

Limiting Post request made on all POST request for Vote, Comment, Share, etc.,

if you want to rate limit the request made for vote,comment,share, etc., you can edit "onefolder/app/Http/Controllers/HomeController.php" file and change middleware code at line no. 31 which looks like below :-

public function __construct() {
	$this->middleware('auth');
}
To :-
public function __construct() {
	$this->middleware(['auth', 'throttle:2,3']);
}

Above code will limit "2" Request per 3 minute. Similarly, If you want to set higher value for request for example 5 request per 2 minute, than you can change `throttle:5,2` and if you want to change minute from 2 to 10, you can do that with `throttle:2,10`.

Restrict no. of Upload user can make per Request [ Optional ]

Lastly, If you want to restrict number of image upload user can upload to  your server,  You can add below line after line no. 324 in "app/Http/Controllers/ImgurController.php"

$count = count($data['file']);
if( $count > 40 ) { return Response::make('Max: 40 image allowed in 1 shot.', 400); }

These are not every one's requirement, thus it was not added by default but are available via options in Documentation. For any question , please leave a comment on our Product page at CodeCanyon here :- https://codecanyon.net/item/image-story-sharing-social-network-imgur-clone/18146331/comments


Loading ...

Related Results :

  1. Installation - ImgSocial
  2. PHP script
  3. Rate Limiting the Post Request
Note :
  • Related Posts are generally User Blog posts.
  • or Other tutorials from other networks of w3clan.com.
  • Any registered user can create related posts based on search term tags.

About the Author