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
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
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
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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.