Jump to content

Show once per IP help


willdikuloz

Recommended Posts

[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

[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

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 "&nbsp;";
};
?>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/28186-show-once-per-ip-help/#findComment-128994
Share on other sites

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 "&nbsp;";
};
?>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/28186-show-once-per-ip-help/#findComment-128997
Share on other sites

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.