GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 07-Apr-2007, 11:41
Richardknox Richardknox is offline
Junior Member
 
Join Date: Nov 2006
Location: Michigan
Posts: 83
Richardknox is on a distinguished road

Need help with IP addresses and a database


Hello,

I have a database that I use to keep track of those that visit my website, and each link that they view, it updates a count so that the next viewer can tell how many people have viewed the link.

I created a script that allows the database to be updated once per day, per link. But I want to prevent the script from updating if certain IP addresses, or a range of ip addresses click on the link. (Google Bot, Yahoo Bot, my home IP).

Like a range of IP addresses.

Here is the script:

PHP Code:

<?
// Viewed.php
// Richard A. Knox
// www.thewebcamsite.net


include "db_connection.php";   //Database connection 
?>
<?php
$dblink = mysql_connect($dbhostname,$dbusername, $dbpassword) OR DIE ("Unable to connect to database! Please try again later.");
mysql_select_db($dbname, $dblink);

// Get the ID number from the end of the ace.php?id=2
$id=$_GET['id'];
$searchIP = mysql_escape_string( $_SERVER['REMOTE_ADDR'] );

// query the database
$query = "SELECT * FROM wcviewed_ip WHERE camid = ($id) LIMIT 0, 30 ";

$result = mysql_query($query,$dblink);

// Testing the results
while ($row=mysql_fetch_row($result))
        {
            if( $row[1]==$searchIP )
            {
                if ($row[3] != date('Y-m-d'))
                {
                // update the database.
            $sql =    "UPDATE
                        `wcviewed_ip`
                    SET
                        `lastdate`=CURDATE()
                    WHERE
                        `ip_bin`=INET_ATON('$searchIP')";
                        
                        $result = mysql_query($query,$dblink);
                        
                        @mysql_unbuffered_query( $sql, $dblink )
            or die( mysql_errno($dblink) . ' - ' . mysql_error($dblink) );
            
// This is where we update the count in the main webcam database.

        $query2 = "SELECT * FROM wcdatabase WHERE id = ($id) LIMIT 0, 30 ";

        $result2 = mysql_query($query2,$dblink);

        $row2 = mysql_fetch_assoc($result2);

        $row2["viewed"]++;
    
        $viewed = $row2["viewed"];

        $query2 = "UPDATE wcdatabase SET viewed = ($viewed) where id = ($id)";

        $result2 = mysql_query($query2, $dblink); 
        return;
                                
                }
                else
                {
                return;
                }
        
        
        }
        
}
       
// Not in the Database, time to insert.
        $sql =    "INSERT INTO
                    `wcviewed_ip`
                    ( `camid`, `ip_bin`, `ip`, `lastdate`)
                    VALUES
                    ( '$id', INET_ATON('$searchIP'), '$searchIP', NOW())";
                    @mysql_unbuffered_query( $sql, $dblink )
            or die( mysql_errno($dblink) . ' - ' . mysql_error($dblink) );
            
            $query2 = "SELECT * FROM wcdatabase WHERE id = ($id) LIMIT 0, 30 ";

        $result2 = mysql_query($query2,$dblink);

        $row2 = mysql_fetch_assoc($result2);

        $row2["viewed"]++;
    
        $viewed = $row2["viewed"];

        $query2 = "UPDATE wcdatabase SET viewed = ($viewed) where id = ($id)";

        $result2 = mysql_query($query2, $dblink); 
       
   

        
?>


Thanks,
Richard
  #2  
Old 07-Apr-2007, 19:39
admin's Avatar
admin admin is offline
Administrator
 
Join Date: Sep 2002
Posts: 841
admin will become famous soon enough

Re: Need help with IP addresses and a database


How are the range of IPs - the ones you want to ignore - stored?

The bots off Google, Yahoo, MSN and others, include many different IP addresses. How do you identify them all?
__________________
Custom BB codes you can use here:
[HTML] | [C++] | [CSS] | [JAVA] | [PY] | [VB]
  #3  
Old 07-Apr-2007, 19:43
lwbbs lwbbs is offline
New Member
 
Join Date: Apr 2007
Location: www.easywebx.com
Posts: 28
lwbbs has a little shameless behaviour in the past

Re: Need help with IP addresses and a database


For web bot, you may try www.crawltrack.fr
  #4  
Old 08-Apr-2007, 08:18
Richardknox Richardknox is offline
Junior Member
 
Join Date: Nov 2006
Location: Michigan
Posts: 83
Richardknox is on a distinguished road

Re: Need help with IP addresses and a database


Right now I have them stored both as regular 76.20.157.253, and I also have them stored in there long format. Here is a snapshot of the database. Now, maybe I shouldn't be worrying about the number of times a link is selected being updated by the Google bots, yahoo bots or whatever. If thats the case, just let me know.

Thanks,
Richard
Attached Images
File Type: jpg ip_addresses.JPG (83.1 KB, 4 views)
  #5  
Old 09-Apr-2007, 10:27
admin's Avatar
admin admin is offline
Administrator
 
Join Date: Sep 2002
Posts: 841
admin will become famous soon enough

Re: Need help with IP addresses and a database


I'll be honest, I really don't understand your question (again).

Anyway, I see a problem with your script:

PHP Code:

// ...

// Get the ID number from the end of the ace.php?id=2
// BAD --> $id=$_GET['id']; replace this with:
$id = intval( $_GET['id'] );

// ... 



There appears to be 2 DB tables in your script and I don't know how they relate.
__________________
Custom BB codes you can use here:
[HTML] | [C++] | [CSS] | [JAVA] | [PY] | [VB]
 
 

Recent GIDBlogAccepted for Ph.D. program by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Selling Server darkneal128 Managed / Dedicated Servers 4 28-Mar-2006 18:01
My Apache Webserver is publicly accessible only from certain IP addresses getwhatUwant Apache Web Server Forum 0 04-Aug-2005 23:06
Memory addresses CyrixOnFire Computer Software Forum - Windows 0 30-Mar-2004 12:50
Links and E-mail addresses in forum vs spam bots BobbyDouglas GIDForums™ 1 29-Feb-2004 16:23

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 17:43.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.