jdock1 Posted June 14, 2011 Share Posted June 14, 2011 Basically what im doing is trying to check if a new users ip exists in the database, if so theup.n it will prevent the account signup. I already have a table with the ip lists, but I need to match them, to see if it already exists. Surely theres a way to do this? I already did my research, so please, don't " " me! Thanks guys!!!! Link to comment https://forums.phpfreaks.com/topic/239307-how-to-check-if-result-exists-in-mysql-table/ Share on other sites More sharing options...
gizmola Posted June 14, 2011 Share Posted June 14, 2011 $query = "SELECT count(*) as countof FROM iptablename WHERE ip = '{$_SERVER['REMOTE_ADDR']}'"; Fetch the result. Really bad idea unless you don't care about stopping people who share an IP (NAT'd) from signing up. Link to comment https://forums.phpfreaks.com/topic/239307-how-to-check-if-result-exists-in-mysql-table/#findComment-1229399 Share on other sites More sharing options...
jdock1 Posted June 14, 2011 Author Share Posted June 14, 2011 $query = "SELECT count(*) as countof FROM iptablename WHERE ip = '{$_SERVER['REMOTE_ADDR']}'"; Fetch the result. Really bad idea unless you don't care about stopping people who share an IP (NAT'd) from signing up. Hmm im not sure I really understand the code. Would it work like this? $query = "SELECT count(*) as countof FROM mytable WHERE ip = '{$_SERVER['REMOTE_ADDR']}'"; mysql_query($link,$query); if ($query) { echo "Duplicate IP"; } So my understanding is that query is looking for the same IP in the table already? If thats so, then my code is valid, if that query is true & it found a matching IP, it echos the error? Also, I have been thinking about that. Do alot ISPs issue the same IP? How common is that? & what do you mean by nat'd? Sorry for all the questions! Thanks for your reply& advice! Link to comment https://forums.phpfreaks.com/topic/239307-how-to-check-if-result-exists-in-mysql-table/#findComment-1229425 Share on other sites More sharing options...
jakebur01 Posted June 14, 2011 Share Posted June 14, 2011 This may be the longer way around than using Count in the query, but doing something like this always works for me. $result = mysql_query("SELECT * FROM iptablename WHERE ip = '{$_SERVER['REMOTE_ADDR']}'", $link); $num_rows = mysql_num_rows($result); if($num_rows>"0") { // do not let them sign up } else { // display signup code } Link to comment https://forums.phpfreaks.com/topic/239307-how-to-check-if-result-exists-in-mysql-table/#findComment-1229521 Share on other sites More sharing options...
gizmola Posted June 14, 2011 Share Posted June 14, 2011 Your code needs to actually look at the result of the count(*) query. $query = "SELECT count(*) as countof FROM mytable WHERE ip = '{$_SERVER['REMOTE_ADDR']}'"; $result = mysql_query($link,$query); if ($result) { $row = mysql_fetch_assoc($result); if ($row['countof'] > 0) { // don't allow signup } else { // do signup } } Link to comment https://forums.phpfreaks.com/topic/239307-how-to-check-if-result-exists-in-mysql-table/#findComment-1229661 Share on other sites More sharing options...
redixx Posted June 14, 2011 Share Posted June 14, 2011 Also, I have been thinking about that. Do alot ISPs issue the same IP? How common is that? & what do you mean by nat'd? Well, colleges/universities, hotels, apartments, Tim Hortons, any place like this that has free internet or some form of networking (like in a college) is most likely going to have one IP. Or at least not a unique IP for every user. So, if one person from a college signs up on your website then nobody else in that college can. Plus, this is a rather useless form of protection because anyone can just go behind a proxy and still sign up multiple accounts. Link to comment https://forums.phpfreaks.com/topic/239307-how-to-check-if-result-exists-in-mysql-table/#findComment-1229685 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.