willdikuloz Posted November 23, 2006 Share Posted November 23, 2006 [code]$ipaddy = $_SERVER['REMOTE_ADDR']; $ipaddy = str_replace('.','',$ipaddy);$query = "SELECT ip FROM ipbase WHERE ip='$ipaddy'";$result = mysql_query($query) or die("mysql error: " . mysql_error());while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {$ipad = $line['ip'];if ( $ipad == $ipaddy ){ echo 'Welcome!';$query = "INSERT INTO ipbase(ip) VALUES('$ipaddy')";$result = mysql_query($query) or die(mysql_error());}else{ echo "";}} [/code] I am having problems where if it is a new user, the Welcome message will not show. I know this is a waste of resources but I am sure for my purpose, it will be worth it. Link to comment https://forums.phpfreaks.com/topic/28186-show-once-per-ip-help/ Share on other sites More sharing options...
marcus Posted November 23, 2006 Share Posted November 23, 2006 [code]<?php$ipaddy = $_SERVER['REMOTE_ADDR']; $ipaddy = str_replace(".","",$ipaddy);$query = "SELECT ip FROM ipbase WHERE ip=$ipaddy";$result = mysql_query($query) or die("mysql error: " . mysql_error()); while ($line = mysql_fetch_assoc($result)) { $ipad = $line['ip']; if ( $ipad == $ipaddy ){ echo 'Welcome!'; $query = "INSERT INTO `ipbase` (`ip`) VALUES('$ipaddy')"; $result = mysql_query($query) or die(mysql_error()); } else { echo ""; } } mysql_free_result($result);?>[/code] Link to comment https://forums.phpfreaks.com/topic/28186-show-once-per-ip-help/#findComment-128985 Share on other sites More sharing options...
willdikuloz Posted November 23, 2006 Author Share Posted November 23, 2006 The Welcome message for some reason will not show even with the modified new code. weird, I don't know what could be wrong. Link to comment https://forums.phpfreaks.com/topic/28186-show-once-per-ip-help/#findComment-128990 Share on other sites More sharing options...
marcus Posted November 23, 2006 Share Posted November 23, 2006 try this:[code]<?php$ipaddy = $_SERVER['REMOTE_ADDR']; $ipaddy = str_replace(".","",$ipaddy);$query = "SELECT ip FROM ipbase WHERE ip=$ipaddy";$result = mysql_query($query) or die("mysql error: " . mysql_error()); $line = mysql_fetch_assoc($result); $ipad = $line['ip']; if ( $ipad == $ipaddy ){ echo 'Welcome!'; $query = "INSERT INTO `ipbase` (`ip`) VALUES('$ipaddy')"; $result = mysql_query($query) or die(mysql_error()); }else { echo " "; };?>[/code] Link to comment https://forums.phpfreaks.com/topic/28186-show-once-per-ip-help/#findComment-128994 Share on other sites More sharing options...
marcus Posted November 23, 2006 Share Posted November 23, 2006 Might I note you should connect to your database (update):[code]<?php$ipaddy = $_SERVER['REMOTE_ADDR']; $ipaddy = str_replace(".","",$ipaddy);$connect = mysql_connect(host,dbuser,dbpass);$db = mysql_select_db(dbname,$connect);$query = "SELECT ip FROM ipbase WHERE ip=$ipaddy";$result = mysql_query($query) or die("mysql error: " . mysql_error()); $line = mysql_fetch_assoc($result); $ipad = $line['ip']; if ( $ipad == $ipaddy ){ echo 'Welcome!'; $query = "INSERT INTO `ipbase` (`ip`) VALUES('$ipaddy')"; $result = mysql_query($query) or die(mysql_error()); }else { echo " "; };?>[/code] Link to comment https://forums.phpfreaks.com/topic/28186-show-once-per-ip-help/#findComment-128997 Share on other sites More sharing options...
willdikuloz Posted November 23, 2006 Author Share Posted November 23, 2006 still nothing, I was messing around with the code a bit, I think it has something to do with the if statements where it's not read them right.[code]$ipaddy = $_SERVER['REMOTE_ADDR']; $ipaddy2 = str_replace(".","",$ipaddy);$connect = mysql_connect(localhost,...,...);$db = mysql_select_db(...,$connect);$query = "SELECT userip FROM ipbase WHERE userip=$ipaddy2";$result = mysql_query($query) or die("mysql error: " . mysql_error()); $line = mysql_fetch_assoc($result); $ipad = $line['ip']; $ipad2 = $ipaddy2; if ( $ipad == $ipad2){echo ''; } if ( $ipad != $ipad2) { echo 'Welcome'; $query = "INSERT INTO `ipbase` (`userip`) VALUES('$ipaddy2')"; $result = mysql_query($query) or die(mysql_error()); };[/code] Link to comment https://forums.phpfreaks.com/topic/28186-show-once-per-ip-help/#findComment-129188 Share on other sites More sharing options...
willdikuloz Posted November 23, 2006 Author Share Posted November 23, 2006 I've messed around with it more, (deleted mysql connect to post this)[code]$ipaddy = $_SERVER['REMOTE_ADDR']; $query = "SELECT userip FROM ipbase WHERE userip = '$ipaddy'";$result = mysql_query($query) or die("mysql error: " . mysql_error()); $line = mysql_fetch_assoc($result); $ipaddy = $_SERVER['REMOTE_ADDR']; $ipad = $line['userip']; if ( $result == '' ){ echo 'Hello!'; $query = "INSERT INTO `ipbase`(`userip`)VALUES('$ipaddy')"; $result = mysql_query($query) or die(mysql_error()); echo "$ipad $ipaddy"; } else { echo " "; };[/code]how can I make the Message show if there is no result? Link to comment https://forums.phpfreaks.com/topic/28186-show-once-per-ip-help/#findComment-129199 Share on other sites More sharing options...
oracle259 Posted November 23, 2006 Share Posted November 23, 2006 try this[code]<?php$ipaddy = $_SERVER['REMOTE_ADDR']; $ipaddy = str_replace(".","",$ipaddy);$query = "SELECT DISTINCT(ip) FROM ipbase WHERE ip=$ipaddy";$result = mysql_query($query) or die("mysql error: " . mysql_error()); while ($line = mysql_fetch_assoc($result)) { $ipad = $line['ip']; if ( $ipad == $ipaddy ){ echo "Welcome ".$ipaddy; } else { echo "Welcome Guest"; $query = "INSERT INTO `ipbase` (`ip`) VALUES('$ipaddy')"; $result = mysql_query($query) or die(mysql_error()); } } mysql_free_result($result);?>[/code] Link to comment https://forums.phpfreaks.com/topic/28186-show-once-per-ip-help/#findComment-129200 Share on other sites More sharing options...
willdikuloz Posted November 23, 2006 Author Share Posted November 23, 2006 hmm, now nothing shows up oracle, why is this damn thing so complicated? Link to comment https://forums.phpfreaks.com/topic/28186-show-once-per-ip-help/#findComment-129203 Share on other sites More sharing options...
willdikuloz Posted November 23, 2006 Author Share Posted November 23, 2006 Nevermind, the DISTINCT(ip) did the trick! thanks so much! Link to comment https://forums.phpfreaks.com/topic/28186-show-once-per-ip-help/#findComment-129205 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.