Dynadot โ€” .com Transfer

Quick question on customizing this script..

SpaceshipSpaceship
Watch
Impact
45
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 <[email protected]>
*
* Examples:
*      [url]http://logohq.net/misc/code/php_counter/[/url]
*      [url]http://logohq.net/misc/code/php_counter/?site=mysite[/url]
*      [url]http://logohq.net/misc/code/php_counter/?site=other[/url]
*
* 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
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
Anyone here know?
:-$
 
0
•••
are they all located under 1 server at the same IP or same 'reseller account' ?
 
0
•••
Yeah, right now all the sites are on the same server (same account)
 
0
•••
Anyone else, out of curiosity?
 
0
•••
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.
 
0
•••
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!
 
0
•••
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 :$
 
0
•••
CatchedCatched
Escrow.com
Spaceship
Rexus Domain
CryptoExchange.com
Domain Recover
CatchDoms
DomainEasy โ€” Zero Commission
DomDB
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back