?
Solved

php code help

Posted on 2011-03-13
13
Medium Priority
?
369 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +3
13 Comments
 
LVL 83

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 83

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
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.

 
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 83

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

Industry Leaders: 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!

Question has a verified solution.

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

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

801 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