<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>scriptygoddess &#187; MT scripts</title>
	<atom:link href="http://www.scriptygoddess.com/archives/category/movable-type/mt-scripts/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.scriptygoddess.com</link>
	<description></description>
	<lastBuildDate>Thu, 08 Dec 2011 18:23:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Number of users currently online (part II)</title>
		<link>http://www.scriptygoddess.com/archives/2004/03/27/number-of-users-currently-online-part-ii/</link>
		<comments>http://www.scriptygoddess.com/archives/2004/03/27/number-of-users-currently-online-part-ii/#comments</comments>
		<pubDate>Sat, 27 Mar 2004 04:00:49 +0000</pubDate>
		<dc:creator>Jennifer</dc:creator>
				<category><![CDATA[MT scripts]]></category>
		<category><![CDATA[WordPress scripts]]></category>

		<guid isPermaLink="false">http://www.scriptygoddess.com/archives/2004/03/27/number-of-users-currently-online-part-ii/</guid>
		<description><![CDATA[I&#039;ve been looking around for &#034;users currently online&#034; type scripts. So, tonight, I hacked together two great scripts. The first comes from Spoono &#8211; this script uses php and mySQL to keep track of how many users are on your site. Then tonight I saw Lynda&#039;s script &#8211; which uses php, a flat file and [...]
No related posts.

Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>I&#039;ve been <a href="http://www.scriptygoddess.com/archives/004895.php">looking around</a> for &#034;users currently online&#034; type scripts. So, tonight, I hacked together two great scripts. The first comes from <a href="http://www.spoono.com/php/tutorials/tutorial.php?id=16">Spoono</a> &#8211; this script uses php and mySQL to keep track of how many users are on your site. Then tonight I saw <a href="http://www.soveryposh.com/blog/2004/03/online_users.php">Lynda&#039;s script</a> &#8211; which uses php, a flat file and makes use of MT&#039;s cookies to actually display WHO is on your site (they would have had to leave a comment on the site to show up in this list)</p>
<p>So I combined the two&#8230;<br />
<span id="more-658"></span><br />
(<b>IMPORTANT NOTE:</b> I&#039;m still working out the kinks with this script. If you use this and have issues &#8211; please email me (scripty aT scriptygoddess dOt nEt) &#8211; don&#039;t leave a comment&#8230; that way the comments section doesn&#039;t get out of hand&#8230; I&#039;d prefer to keep the comments section reversed for either modifications/alternate hacks or additional suggestions)</p>
<p>Here is the modified &#034;create table&#034; script</p>
<p><code>CREATE TABLE useronline (<br />
timestamp int(15) DEFAULT '0' NOT NULL,<br />
ip varchar(40) NOT NULL,<br />
file varchar(100) NOT NULL,<br />
userName varchar(50) NOT NULL,<br />
userURL varchar(100) NOT NULL,<br />
PRIMARY KEY (timestamp),<br />
KEY ip (ip),<br />
KEY file (file)<br />
);</code></p>
<p>The way the <a href="http://www.spoono.com/php/tutorials/tutorial.php?id=16">Spoono&#039;s original script</a> worked was that it would (I believe) only tell you how many users were on a <i>particular page</i> &#8211; but the way my script below works is that it shows users on the entire site&#8230;</p>
<p>On Lynda&#039;s site, she pointed out that you need to modify the &#034;rememberme&#034; and &#034;forgetme&#034; javascript functions. <a href="http://www.soveryposh.com/x/blog/online_users/">See her site for the details.</a></p>
<p>Now here&#039;s the updated script. (I made this a seperate file and put it on my site as an include where I wanted to the &#034;users on site&#034; to display)</p>
<p><code>&lt;?php<br />
//fill in some basic info<br />
$dbsvr= "localhost";<br />
$dbusrnam = "your-database-username";<br />
$dbpswrd = "your-database-password";<br />
$database = "your-database-name";<br />
$timeoutseconds = 300;<br />
$mt_name = isset($_COOKIE['mtcmtauth']) ? ($_COOKIE['mtcmtauth']) : "";<br />
$mt_url = isset($_COOKIE['mtcmthome']) ? ($_COOKIE['mtcmthome']) : "";<br />
$mt_ip = getenv("HTTP_X_FORWARDED_FOR") ? getenv("HTTP_X_FORWARDED_FOR") : getenv("REMOTE_ADDR");<br />
// If someone doesn't want their name to appear on the list, enter their<br />
// urls below, separated by a comma.  Example:<br />
// $blocked_urls = "http://www.domain1.com, http://www.domain2.com";<br />
$blocked_urls = "";<br />
// If user is in blocked report above, make them anonymous and then add to file<br />
if ($blocked_urls !="") {<br />
$blocked = explode(",", $blocked_urls);<br />
for ($i=0; $i &lt; count($blocked); $i++) {<br />
if (trim($blocked[$i]) == $mt_url) {<br />
$mt_name = "";<br />
$mt_url = "";<br />
}<br />
}<br />
}<br />
//get the time<br />
$timestamp = time();<br />
$timeout = $timestamp-$timeoutseconds;<br />
//connect to database<br />
mysql_connect($dbsvr, $dbusrnam, $dbpswrd);<br />
//insert the values<br />
$insert = mysql_db_query($database, "INSERT INTO useronline VALUES<br />
('$timestamp','$mt_ip ','','$mt_name','$mt_url');");<br />
if(!($insert)) {<br />
print "Useronline Insert Failed &gt; ";<br />
}<br />
//delete values when they leave<br />
$delete = mysql_db_query($database, "DELETE FROM useronline WHERE timestamp &lt; $timeout");<br />
if(!($delete)) {<br />
print "Useronline Delete Failed &gt; ";<br />
}<br />
//grab the results<br />
$result = mysql_db_query($database, "SELECT DISTINCT ip, userName, userURL FROM useronline");<br />
if(!($result)) {<br />
print "Useronline Select Error &gt; ";<br />
}<br />
//number of rows = the number of people online<br />
$user = mysql_num_rows($result);<br />
$display = "";<br />
$annon = 0;<br />
mysql_close();<br />
for ($i = 0; $i &lt; $user; $i++) {<br />
$row= mysql_fetch_array($result);<br />
if ($row["userName"] != "" &#038;&#038; $row["userURL"] != "") {<br />
//make sure url has "http://" in it<br />
$isHttpUrl = strpos($row["userURL"], "http://");<br />
if ($isHttpUrl === false) {<br />
    $row["userURL"] = "http://".$row["userURL"];<br />
}<br />
$display .= "&lt;a href=&#92;"".$row['userURL']."&#92;"&gt;".$row["userName"] ."&lt;/a&gt;&lt;br /&gt;";<br />
} else if ($row["userName"] != "") {<br />
$display .= $row["userName"] ."&lt;br /&gt;";<br />
} else {<br />
$annon++;<br />
}<br />
}<br />
if ($display != "") {<br />
echo $display;<br />
}<br />
if ($annon != "") {<br />
echo $annon;<br />
if ($annon &lt;= 1) {<br />
echo " user";<br />
} else {<br />
echo " users";<br />
}<br />
}<br />
?&gt;</code></p>
<p><b>To use this script with wordpress, change these two lines in the script above:</b></p>
<p><code>$mt_name = isset($_COOKIE['mtcmtauth']) ? ($_COOKIE['mtcmtauth']) : "";<br />
$mt_url = isset($_COOKIE['mtcmthome']) ? ($_COOKIE['mtcmthome']) : "";</code></p>
<p>To this:</p>
<p><code>$mt_name = (isset($_COOKIE['comment_author_'.$cookiehash])) ? trim($_COOKIE['comment_author_'.$cookiehash]) : '';<br />
$mt_url = (isset($_COOKIE['comment_author_url_'.$cookiehash])) ? trim($_COOKIE['comment_author_url_'.$cookiehash]) : '';</code></p>
<p>(yes, I know the variables still say &#034;mt&#034; in them &#8211; if that really confuses you, just do a find and replace and change them.</p>
<p>If you have MOVED OVER from MT to WP &#8211; and still want to capture the names of people who may or may not have left a comment on your wordpress blog yet (so they don&#039;t have cookies from wp comments &#8211; but probably still have MT cookies), change those lines to this instead:</p>
<p><code>$mt_name = (isset($_COOKIE['comment_author_'.$cookiehash])) ? trim($_COOKIE['comment_author_'.$cookiehash]) : '';<br />
if ($mt_name == '') {<br />
	$mt_name = isset($_COOKIE['mtcmtauth']) ? ($_COOKIE['mtcmtauth']) : "";<br />
}<br />
$mt_url = (isset($_COOKIE['comment_author_url_'.$cookiehash])) ? trim($_COOKIE['comment_author_url_'.$cookiehash]) : '';<br />
if ($mt_url == '') {<br />
	$mt_url = isset($_COOKIE['mtcmthome']) ? ($_COOKIE['mtcmthome']) : "";<br />
}</code></p>
<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.scriptygoddess.com/archives/2004/03/27/number-of-users-currently-online-part-ii/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
	</channel>
</rss>

