NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page Quick question on customizing this script..

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

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 05-07-2005, 11:27 PM THREAD STARTER               #1 (permalink)
Senior Member
 
Ringr's Avatar
Join Date: Jul 2004
Posts: 1,383
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 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.
????: NamePros.com http://www.namepros.com/programming/88551-quick-question-on-customizing-this-script.html

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)
????: NamePros.com http://www.namepros.com/showthread.php?t=88551
// 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, 11:25 AM THREAD STARTER               #2 (permalink)
Senior Member
 
Ringr's Avatar
Join Date: Jul 2004
Posts: 1,383
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 beholdRingr is a splendid one to behold
 



Anyone here know?
:-$
Ringr is offline  
Old 05-08-2005, 11:41 AM   #3 (permalink)
Pro Coder & Designer
 
aween's Avatar
Join Date: Apr 2005
Location: Netherlands
Posts: 967
aween is just really niceaween is just really niceaween is just really niceaween is just really niceaween is just really niceaween is just really niceaween is just really niceaween is just really nice
 



are they all located under 1 server at the same IP or same 'reseller account' ?
__________________
aween web development
aween is offline  
Old 05-08-2005, 01:14 PM THREAD STARTER               #4 (permalink)
Senior Member
 
Ringr's Avatar
Join Date: Jul 2004
Posts: 1,383
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 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, 09:33 PM THREAD STARTER               #5 (permalink)
Senior Member
 
Ringr's Avatar
Join Date: Jul 2004
Posts: 1,383
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 beholdRingr is a splendid one to behold
 



Anyone else, out of curiosity?
Ringr is offline  
Old 05-11-2005, 09:39 PM   #6 (permalink)
Senior Member
Join Date: Mar 2005
Location: canada
Posts: 1,045
skrilla is just really niceskrilla is just really niceskrilla is just really niceskrilla is just really niceskrilla is just really niceskrilla is just really niceskrilla is just really niceskrilla is just really nice
 


Protect Our Planet Child Abuse
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.
__________________
Add Me to G+
skrilla is offline  
Old 05-14-2005, 06:42 PM   #7 (permalink)
NamePros Member
Join Date: May 2005
Location: Osaka, Japan
Posts: 37
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, 08:57 PM THREAD STARTER               #8 (permalink)
Senior Member
 
Ringr's Avatar
Join Date: Jul 2004
Posts: 1,383
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 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


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 10:48 AM
Domain Rating Script for Sale : $200.00 - only 10 scripts will be sold fonzerelli_79 Scripts For Sale 3 08-31-2003 09:41 AM

Liquid Web Smart Servers  
All times are GMT -7. The time now is 11:02 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger