One Download Per IP?

Status
Not open for further replies.

MrLogic

Member
Nov 28, 2012
118
4
Hello,I was wondering if anyone knows how to make a PHP script(or what ever language)to allow one download per IP.So if you know,please tell me.Thanks
 

xHissy

PHP / VB.net Developer
Oct 23, 2011
75
5
The best way I think you could do would be to make a DB with a table for downloads.
And when someone downloads it add their IP to the database.

Then before they download it check the DB to see if the IP exists. If it doesn't insert it and allow the download.
 

JoshuaLuke

Posting Freak
Jan 29, 2012
529
51
Code:
<?php
if(mysql_num_rows(mysql_query("SELECT * FROM downloads_log WHERE ip = '" . $_SERVER['REMOTE_ADDR'] . "')) == 1) {
// what you wanna do
}
?>

something like that, might not be exactly right as i just wrote it
 

Weasel

👄 I'd intercept me
Nov 25, 2011
4,135
2,461
Code:
<?php
if(mysql_num_rows(mysql_query("SELECT * FROM downloads_log WHERE ip = '" . $_SERVER['REMOTE_ADDR'] . "')) == 1) {
// what you wanna do
}
?>

something like that, might not be exactly right as i just wrote it

That seems about right, a little update:
PHP:
<?php
$download_amount = 1 // How many downloads are allowed per IP
$download_amount_per_ip_query = "SELECT * FROM downloads WHERE ip = '".$_SERVER['REMOTE_ADDR']."'";
$download_amount_per_ip = mysql_num_rows($download_amount_per_ip_query);
 
if($download_amount_per_ip >= $download_amount) {
echo "You already downloaded the max amount of downloads possible per IP";
}
?>
 

JoshuaLuke

Posting Freak
Jan 29, 2012
529
51
That seems about right, a little update:
PHP:
<?php
$download_amount = 1 // How many downloads are allowed per IP
$download_amount_per_ip_query = "SELECT * FROM downloads WHERE ip = '".$_SERVER['REMOTE_ADDR']."'";
$download_amount_per_ip = mysql_num_rows($download_amount_per_ip_query);
 
if($download_amount_per_ip >= $download_amount) {
echo "You already downloaded the max amount of downloads possible per IP";
}
?>

There needs to be a mysql_query after the num rows
 

Heaplink

Developer & Designer
Nov 9, 2011
510
173
Why not just use MySQLi or PDO - better security, less work & cleaner code (using a wrapper) - With COUNT() function in SQL you can get the number of rows of the column

e.g. SELECT COUNT(`ip_addr`) WHERE `ip_addr` = ?
 

Sean

‫‫‫‫‫‫  ‫  Don't Worry, Be Happy
Dec 12, 2011
1,121
405
Why not just use MySQLi or PDO - better security, less work & cleaner code (using a wrapper) - With COUNT() function in SQL you can get the number of rows of the column

e.g. COUNT(`ip_addr`) or COUNT(*)
Yeah mysqli is an easier and better way to go :up:
 

Jian

Resident Weeb
Contributor
Sep 2, 2011
687
437
Some users have static IP, which means it changes everyday. Maybe you can record the current IP address in a database and store a cookie in their browser at the same time?
 
Status
Not open for further replies.

Users who are viewing this thread

Top