?
Solved

php code help

Posted on 2011-03-13
13
Medium Priority
?
375 Views
Last Modified: 2012-05-11
Hi,

How to make code to detect if a ip address is sending more requests; example: if any ip address send 10 requests in 2 seconds then code should catch it?

Any code idea or sample?

Thanks
0
Comment
Question by:sindhuxyz
  • 4
  • 3
  • 2
  • +3
13 Comments
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 35123692
Note that you will get a separate request for every file referenced on your page.  If you have 10 files including the main, the CSS file, javascript files, and image files, then you will get 10 requests just for one page.
0
 
LVL 5

Author Comment

by:sindhuxyz
ID: 35123752
We can conclude, how many files are referenced, just need sample to check if there are more request from one ip address,

0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 35123817
On http://www.php.net/manual/en/reserved.variables.server.php, look at 'REMOTE_ADDR'.  You can view it like below.  You would have to create a way to keep track of it in a file or a database.
<?php
echo $_SERVER['REMOTE_ADDR'];
?>

Open in new window

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 34

Expert Comment

by:Beverley Portlock
ID: 35123958
SIgn up for Google Analytics - that will tell you how often a page is hit and can give IP and geo maps as well. All you need to do is to embed the UA code in the page.
0
 
LVL 5

Author Comment

by:sindhuxyz
ID: 35123976
Is it possible to use session values to store ip address woth request counts, if request count is greater than a value then refuse connection
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 35123989
If this is related to your question about getting 30,000 requests per second, PHP is not going to be fast enough to handle this.  You will need to look at methods in the server software or possibly the firewall that originally gets the requests.
0
 
LVL 12

Accepted Solution

by:
Mohamed Abowarda earned 750 total points
ID: 35124882
You can use the database to store log for each IP Address requests, for example:
IP Address 127.0.0.1 made first request:
Add record:
----------------------------------
IPAddress          Count
----------------------------------
127.0.0.1            1

The same IP Address made another request, update the record
----------------------------------
IPAddress          Count
----------------------------------
127.0.0.1            2
0
 
LVL 15

Assisted Solution

by:Insoftservice
Insoftservice earned 375 total points
ID: 35125760
0
 
LVL 15

Expert Comment

by:Insoftservice
ID: 35125767
Hi,
It depends upon ur server and has to be done by server admin.
But it can be even manage via the link provided. and later redirect it to the script where captcha validation is available..
Hope it helps u
0
 
LVL 5

Author Comment

by:sindhuxyz
ID: 35126975
@:Medo3337

I want to do what u have mentioned but using session variables instead of using database. Please let me know how to do this using session variables and what code will help
0
 
LVL 12

Assisted Solution

by:Mohamed Abowarda
Mohamed Abowarda earned 750 total points
ID: 35127732
To do the same way using session variable use the follow code:
// Execute the following code when the visitor make any new request
session_start();
if (!isset($_SESSION['requestsCount']))
{
	$_SESSION['requestsCount'] = 1;
} else {
	$_SESSION['requestsCount']++;
}

// You can use $_SESSION['requestsCount'] to get the number of requests

Open in new window

0
 
LVL 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 375 total points
ID: 35127937
Is it possible to use session values to store ip address

Not if I understand your inquiry correctly.  A session is started per unique browser request.  So if I run a script that does 100 requests with 100 different file_get_contents() or CURL statements, you are totally dependent on my script to act like a well-behaved browser, accepting the session cookies and returning them to your server.  I do not believe that you can depend on that, and therefore the session is the wrong tool.  The data base is the right tool.

The $_SERVER["REMOTE_ADDR"] variable is not immutable, but it is probably good enough for most uses.  If you need more protection than this, consider adding a form to your script and requiring the client to submit a CAPTCHA test before proceeding.
0
 
LVL 5

Author Closing Comment

by:sindhuxyz
ID: 35236777
thanks
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses
Course of the Month15 days, 1 hour left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question