Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
PHP Counter Script - Not excluding my IP
Old 03-01-2008, 08:13 AM PHP Counter Script - Not excluding my IP
Gilligan's Avatar
Website Designer

Posts: 1,670
Name: Stefan
Location: London, UK
Trades: 0
I got a script to counter the users on my website, and i adds stats into my MySQL database.

I've set it so it doesn't add stats for my IP, but that doesn't seem to work.

PHP Code:
<?php 

 
// database configuration 

    
include('/websites/LinuxPackage02/gk/s_/uk/gks.uk.com/public_html/1/includes/db.php');

// Connect to database

    
dbConnect();
    
// Excludes self IP

if ($REMOTE_ADDR != 'my.ip.add.ress'){    

// Add to database

    
date_default_timezone_set('GMT');
    
$datetime date('d M Y h:i:s a');
    
$querystat "INSERT INTO countstats (Name, IP, DateTime)
                                               VALUES('About the Author', '
$REMOTE_ADDR', '$datetime')";
    
$resultstat mysql_query($querystat);
    if (!
$result){ 
        echo 
mysql_error() ;    
    }
            


?>

HTML 
Content 
for 
site 
here
of course 'my.ip.add.ress' actually contains my ip address, but I don't want to give that information out on here.

Can anyone see what this is logging my IP when it shouldn't.
Gilligan is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-01-2008, 10:28 AM Re: PHP Counter Script - Not excluding my IP
dlaroche22's Avatar
Skilled Talker

Posts: 84
Name: Dustin Laroche
Trades: 0
I would give this a try:

PHP Code:
<?php 
 
 
// database configuration 
 
    
include('/websites/LinuxPackage02/gk/s_/uk/gks.uk.com/public_html/1/includes/db.php');
 
// Connect to database
 
    
dbConnect();
 
// Gets the IP address
 
$ip getenv("REMOTE_ADDR");
 
 
// Excludes self IP
 
if ($ip != 'my.ip.add.ress'){    
 
// Add to database
 
    
date_default_timezone_set('GMT');
    
$datetime date('d M Y h:i:s a');
    
$querystat "INSERT INTO countstats (Name, IP, DateTime)
                                               VALUES('About the Author', '
$REMOTE_ADDR', '$datetime')";
    
$resultstat mysql_query($querystat);
    if (!
$result){ 
        echo 
mysql_error() ;    
    }
 

 
?>
__________________
Under Construction, But A Work In Progress
Webhosting isn't cheap, sponsors are important

Please login or register to view this content. Registration is FREE
dlaroche22 is offline
Reply With Quote
View Public Profile
 
Old 03-01-2008, 11:04 AM Re: PHP Counter Script - Not excluding my IP
Gilligan's Avatar
Website Designer

Posts: 1,670
Name: Stefan
Location: London, UK
Trades: 0
thanks, worked.

just one more thing...why didn't my first one work?
Gilligan is offline
Reply With Quote
View Public Profile
 
Old 03-01-2008, 11:10 AM Re: PHP Counter Script - Not excluding my IP
dlaroche22's Avatar
Skilled Talker

Posts: 84
Name: Dustin Laroche
Trades: 0
This piece of code just creates a variable named REMOTE_ADDR.
PHP Code:
if ($REMOTE_ADDR != 'my.ip.add.ress'
In order to access or obtain a global variable such as $REMOTE_ADDR you will want to use the function getenv("REMOTE_ADDR").
__________________
Under Construction, But A Work In Progress
Webhosting isn't cheap, sponsors are important

Please login or register to view this content. Registration is FREE

Last edited by dlaroche22; 03-01-2008 at 11:11 AM..
dlaroche22 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to PHP Counter Script - Not excluding my IP
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.18597 seconds with 12 queries