[???] Allowing only one visit per IP address ...

OTrap

Elite Member
Joined
Jul 12, 2008
Messages
2,314
Reaction score
1,064
I'm presuming to do this with an if/else statement, predominantly because I'm still something of a PHP novice.

What I'm wanting to do is this:

Visitor A comes to my site. His IP address is 111.111.111.111. He fills in an opt-in form. He then attempts to go to the initial page again and submit ANOTHER set of details in the form.

I'd like to be able to show a different page of code if the IP has been tracked before. Something like this:

PHP:
<?php 

get visitor's IP address;

check his IP address against a database;


if his IP shows up on the database {

echo "You've been here before.";

} else {

echo "Hey; you are new!";

}

write the visitor's IP address to the database;

?>

Am I biting off more than I should be by wanting to do this? If it's too complicated, I wouldn't want anyone to put too much time into explaining it, but if it's a quick or simple process, I'd sure love some help.
 
Man, thank you guys for your help.

OldFatGuy, there is indeed a reason for tracking the IP. ;)
 
I might not be answering your question.

But just a note here, as mentioned by OldFatGuy, you should use a cookie at least.
Of course you can combine with a ip check as well.
The reason is because different machines may have the same ip (e.g. they go through same subnet, proxy etc) and in other case, those dynamic connection (adsl or mobile), the ip from same machine may change.
 
The distinction in IP address is actually more important than the distinction in user. However, I will use cookies as well, as it certainly will only make things more genuine.

Much appreciated guys! I've got it worked out!

This place is awesome.
 
This is some PHP I used on one of my old sites.

I was using a MySql Database, and recorded the IP when a person registered.

Everytime someone registered it would check the database to see if that IP had been used before.

Its a basic way of doing it, but it works, the bold text are my notes, it was written this way to suit other stuff going on in the script, but it can be used and changed to suit you if you use php and mysql.

$userip=$_SERVER['REMOTE_ADDR']; it would pickup the users ip
$sql9 = "select * from `users` where `IP` = '$userip'"; it would check the database for that ip
$result9 = mysql_query($sql9); the result would store in $result9
$total9 = mysql_num_rows($result9); $total9 would equal how many times the ip address had been found
$rs9 = mysql_fetch_row($result9);


if ($total9 > 0) {
$check=9;
}

if ($total > 0) {
$check=1;
}
 
Back
Top