[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.


Closed Thread
 
LinkBack Thread Tools
Old 05-07-2005, 10:27 PM   #1 (permalink)
Senior Member
 
Ringr's Avatar
 
Join Date: Jul 2004
Posts: 1,391
1,090.86 NP$ (Donate)

Ringr is a splendid one to beholdRingr is a splendid one to beholdRingr is a splendid one to beholdRingr is a splendid one to beholdRingr is a splendid one to beholdRingr is a splendid one to beholdRingr is a splendid one to behold


Quick question on customizing this script..

Hey guys,

I need help on the script below (I already have the MySQL table structure and whatnot, I just need to figure out how to make this work with my network):
Code:
<?php

/**
* A simple visitor tracking script for use on multiple sites (a network).
*
* Copyright 2004 Peter Cowburn <peter@cowburn.info>
*
* Examples:
*      http://logohq.net/misc/code/php_counter/
*      http://logohq.net/misc/code/php_counter/?site=mysite
*      http://logohq.net/misc/code/php_counter/?site=other
*
* Any additions/modifications/distribution of this material is
* allowed without contacting the original author or crediting of the
* original author.
*/

/**
* A simple error handling function
*
* @param     string            $str     Message to be displayed.
* @param     string/integer    $line    (Optional) Line number of error.
* @return    void                       Prints error message and halts all processing.
*/
function mysql_die($str, $line=null) {
  $friendly = 'An error has occured and all page processing has been halted.';
  if ($line !== null) {
    $str = 'Line ' . $line . ': ' . $str;
  }
  $msg = sprintf('<p>%s</p><code>%s</code>', $friendly, $str);
  die ($msg);
}

// holder for mysql preferences
// *** CHANGE THESE! ***
$mysql = array (
  'host'  => 'mysql.mynetwork.com', // or, localhost?..
  'user'  => 'username',
  'pass'  => 'password',
  'db'    => 'dbCounter',
  'table' => 'tCount'
);

// holder for our visitor's data
$data = array (
  'ip'   => $HTTP_SERVER_VARS['REMOTE_ADDR'],
);


// Information for "default" hits
$default_site = array (
  'key'  => 'yaxay',
  'name' => 'yaXay.com'
);

// Allowing other sites in on the act (via query string)
// Follows pattern:
//   mysql_store_name => html_display_name
$sites = array (
  'mysite'  => 'www.MySite.com',
  'other'   => 'www.MyOtherSite.com'
);

if (($_GET['site'] == '') || (array_key_exists($_GET['site'], $sites) === false)) {
  $site_key  = $default_site['key'];
  $site_name = $default_site['name'];
} else {
  $site_key  = preg_replace('#[^a-zA-Z0-9_]+#', '', $_GET['site']);
  $site_name = $sites[$site_key];
}

// holder for general preferences
$prefs = array (
  // how long do we recognise a "visitor" for? (minutes)
  'timeout'      => 15,
  // site name in the DB
  'tSite'        => $site_key,
  // Friendly site name
  'fSite'        => $site_name,
  // Friendly network name
  'fNet'         => 'MyNetwork',
  // Friendly message
  'fMess'        => '<p>Visitor count for %s: %d</p>',
  // Show friendly messages? (true/false)
  'showMessages' => true
);

// Holder for our visitor counts
$count = array (
  'site' => 0,
  'net'  => 0
);

// Connect to host and DB
$conn =  mysql_connect($mysql['host'], $mysql['user'], $mysql['pass'])
  or mysql_die('Cannot connect to database host.', __LINE__);

$db = mysql_select_db($mysql['db'], $conn)
  or mysql_die('Could not select database to retrieve data.', __LINE__);

// Check if the user has already been logged and is still "active"
$sql = sprintf("SELECT * FROM %s WHERE ip='%s' AND site='%s' AND DATE_SUB(NOW(),INTERVAL %s MINUTE)<=stamp;", $mysql['table'], $data['ip'], $prefs['tSite'], $prefs['timeout']);
$result = mysql_query($sql, $conn) or mysql_die('Could not check visitor table.', __LINE__);

if (mysql_num_rows($result) > 0) {
  $record = mysql_fetch_object($result);
  // Visitor already here... so update to current time
  $sql = sprintf("UPDATE %s SET stamp=NOW() WHERE site='%s' AND ip='%s' AND stamp='%s';", $mysql['table'], $prefs['tSite'], $data['ip'], $record->stamp);
  mysql_query($sql, $conn) or mysql_die('Could not update timestamp.', __LINE__);
} else {
  // A new visitor, so lets add them
  $sql = sprintf("INSERT INTO %s SET ip='%s', site='%s';", $mysql['table'], $data['ip'], $prefs['tSite']);
  mysql_query($sql, $conn) or mysql_die('Could not log visitor.', __LINE__);
}


// Now lets count our active users on the site...
$sql = sprintf("SELECT COUNT(ip) as total FROM %s WHERE site='%s' AND DATE_SUB(NOW(),INTERVAL %s MINUTE)<=stamp;", $mysql['table'], $prefs['tSite'], $prefs['timeout']);
$result = mysql_query($sql, $conn) or mysql_die('Error gathering local stats.', __LINE__);
$count['site'] = mysql_result($result, 0);

// ... and on the entire network!
$sql = sprintf("SELECT COUNT(ip) as total FROM %s WHERE DATE_SUB(NOW(),INTERVAL %s MINUTE)<=stamp;", $mysql['table'], $prefs['timeout']);
$result = mysql_query($sql, $conn) or mysql_die('Error gathering network stats.', __LINE__);
$count['network'] = mysql_result($result, 0);

// If we chose to show the counts
if ($prefs['showMessages'] == true) {
  // Tell the world what we have found out!
  printf($prefs['fMess'], $prefs['fSite'], $count['site']);
  printf($prefs['fMess'], $prefs['fNet'], $count['network']);
}

// Don't forget to close the DB connection
@mysql_close($conn);

// And finish.
exit;

?>
Okay, so I have a network - it is made up of about 12 diff sites. How would I make this script work? This script is made to count the people online one specific site, and then how many on the rest of the other sites (the network) and show both statistics.

Would I add my network sites to this area of the code, and make it look like this - or am I wrong? :
// Allowing other sites in on the act (via query string)
// Follows pattern:
// mysql_store_name => html_display_name
$sites = array (
'site1' => 'www.site1.com',
'site2' => 'www.site2.com',
'site3' => 'www.site3.com',
'site4' => 'www.site4.com',
'site5' => 'www.site5.com',
'site6' => 'www.site6.com',
(etc, etc, until I go to site 12)

I'm really confused on how to set this up and how to have it work with each domain on my network using only one installation..

Please help,
Thanks,
Andy
Ringr is offline  
Old 05-08-2005, 10:25 AM   #2 (permalink)
Senior Member
 
Ringr's Avatar
 
Join Date: Jul 2004
Posts: 1,391
1,090.86 NP$ (Donate)

Ringr is a splendid one to beholdRingr is a splendid one to beholdRingr is a splendid one to beholdRingr is a splendid one to beholdRingr is a splendid one to beholdRingr is a splendid one to beholdRingr is a splendid one to behold


Anyone here know?
:-$
Ringr is offline  
Old 05-08-2005, 10:41 AM   #3 (permalink)
Pro Coder & Designer
 
xlusive's Avatar
 
Join Date: Apr 2005
Location: Netherlands
Posts: 964
101.50 NP$ (Donate)

xlusive is just really nicexlusive is just really nicexlusive is just really nicexlusive is just really nicexlusive is just really nice


are they all located under 1 server at the same IP or same 'reseller account' ?
__________________
Online Dragonball Game
xlusive is offline  
Old 05-08-2005, 12:14 PM   #4 (permalink)
Senior Member
 
Ringr's Avatar
 
Join Date: Jul 2004
Posts: 1,391
1,090.86 NP$ (Donate)

Ringr is a splendid one to beholdRingr is a splendid one to beholdRingr is a splendid one to beholdRingr is a splendid one to beholdRingr is a splendid one to beholdRingr is a splendid one to beholdRingr is a splendid one to behold


Yeah, right now all the sites are on the same server (same account)
Ringr is offline  
Old 05-11-2005, 08:33 PM   #5 (permalink)
Senior Member
 
Ringr's Avatar
 
Join Date: Jul 2004
Posts: 1,391
1,090.86 NP$ (Donate)

Ringr is a splendid one to beholdRingr is a splendid one to beholdRingr is a splendid one to beholdRingr is a splendid one to beholdRingr is a splendid one to beholdRingr is a splendid one to beholdRingr is a splendid one to behold


Anyone else, out of curiosity?
Ringr is offline  
Old 05-11-2005, 08:39 PM   #6 (permalink)
Senior Member
 
Join Date: Mar 2005
Location: canada
Posts: 1,020
591.76 NP$ (Donate)

skrilla is just really niceskrilla is just really niceskrilla is just really niceskrilla is just really nice


I'm actually trying to figure out the same thing, i only have 2 sites on one account though..If you get this script working let me know..I would love to have what you are trying to accomplish.
__________________
RB's Lingerie
COME VISIT NOW!!! Sign up for adsense at www.ratemymug.com
This line is for sale PM for details
skrilla is offline  
Old 05-14-2005, 05:42 PM   #7 (permalink)
NamePros Member
 
Join Date: May 2005
Location: Osaka, Japan
Posts: 37
69.00 NP$ (Donate)

df-sean is an unknown quantity at this point


Can you please explain what exactly isn't working? I scanned through your code, but without spending a lot of time on it, it's tough to see where the trouble is. Can you try to make your question more specific or post a much simpler script to illustrate what's not working? Cheers!
__________________
:::: *DataFly.Net *::::
Rock-Solid Linux Web Hosting

http://www.datafly.net
df-sean is offline  
Old 05-19-2005, 07:57 PM   #8 (permalink)
Senior Member
 
Ringr's Avatar
 
Join Date: Jul 2004
Posts: 1,391
1,090.86 NP$ (Donate)

Ringr is a splendid one to beholdRingr is a splendid one to beholdRingr is a splendid one to beholdRingr is a splendid one to beholdRingr is a splendid one to beholdRingr is a splendid one to beholdRingr is a splendid one to behold


It's mainly just the setting-it-up part that I am confused about.
I have 12 different sites in my network and I want them all to use this coding and for it to say how many are on one of those 12 sites and how many are on all of the sites put together, I hope that kind of makes sense :$
Ringr is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
60.000 Templates, scripts, fonts, banners etc. $9.95 atkims Web Development Wanted 19 11-16-2004 09:48 AM
Domain Rating Script for Sale : $200.00 - only 10 scripts will be sold fonzerelli_79 Scripts For Sale 3 08-31-2003 08:41 AM

Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 12:26 AM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85