Solved

php code help

Posted on 2011-03-13
13
318 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 82

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 82

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

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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 12

Accepted Solution

by:
Mohamed Abowarda earned 250 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 125 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 250 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 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 125 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now