Location: PHPKode > scripts > Users online > users-online/install.php
<?
ob_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Users Online PHP script - Installer</title>
<style type="text/css">
<!--
body {
	margin:0 auto;
	padding:10px;
	font-family:Geneva, Arial, Helvetica, sans-serif;
	font-size:1.0em;
}
div#wrapper {
	width:50%;
	margin:0 auto;
	padding:0;
}
span.success {
	font-weight:bold;
	color:#339900;
}
span.error {
	font-weight:bold;
	color:#ff0000;
}
span.sqlerror strong, span.tip strong {
	display:block;
	padding:5px;
	background-color:#ccc;
}
span.sqlerror, span.tip {
	border:1px solid #ccc;
	margin-top:10px;
	display:block;
	font-size:0.9em;
}
span.sqlerror span, span.tip span {	
	display:block;
	padding:5px;
}
span.sqlerror strong {
	background-color:#3399CC;
}
span.sqlerror {
	border:1px solid #3399CC;
}
em {
	background-color:#ddd;
	font-family:"Courier New", Courier, monospace;
}
h1 {
	border-bottom:1px solid #ddd;
	font-size:1.4em;
	color:#333;
}
a {
	font-size:0.9em;
	color:#ffffff;
	background-color:#333333;
	padding:3px;
	text-decoration:none;
}
//-->
</style>
</head>

<body>
<div id="wrapper">
<h1>Installing</h1>
<?php

	require_once('online.php');
	
	/* installer vars */
	$install_step = (int) $_GET['step'];
	
	$success = '<span class="success">Success!</span><br />';
	$fail    = '<span class="error">Failed!</span><br />';
	
	$sql_error = '<br /><span class="sqlerror"><strong>MySQL said:</strong><span>%s</span></span><br />';
	
	$tip  = '<span class="tip"><strong>Tip:</strong><span>%s</span></span>';
	$code = '<span class="tip"><strong>Code:</strong><span>%s</span></span>';
	
	$continue = '<br /><a href="install.php?step=%d">Continue &raquo;</a>';
	
	if($install_step == 1 || $install_step == 0)
	{
	
		echo 'Testing connection....';
		
		if(!$link)
		{
			echo $fail;
			echo(sprintf($sql_error, mysql_error()));
			echo(sprintf($tip, 'Check your <em>$db</em> settings in <em>online.php</em><br />Refresh this page to try again'));
			
		}
		else 
		{
			echo $success;
			echo 'Testing database....';
			
			if(!$dbl)
			{
				echo $fail;
				echo(sprintf($sql_error, mysql_error()));
				echo(sprintf($tip, 'Check your <em>$db</em> settings in <em>online.php</em><br />Make sure the database exists - this installer will <em>not</em> create it for you. See your web hositng control panel.<br />Refresh this page to try again'));
			}
			else
			{
				echo $success;
				echo(sprintf($continue, 2));
				
			}
		}

	}
	
	
	if($install_step == 2)
	{
		if(!$link || !$dbl)
		{
			header("Location: install.php");
			exit;
		}
		
		echo 'Creating table...';
		
		$sql = 'CREATE TABLE IF NOT EXISTS `' . UO_TABLE . '` (
				  `id` varchar(100) NOT NULL,
				  `online` int(20) NOT NULL
				)';
				
		$result = mysql_query($sql, $link);
		
		if(!$result)
		{	
			echo $fail;
			echo(sprintf($sql_error, mysql_error()));
			echo(sprintf($tip, 'Check your <em>$db</em> settings in <em>online.php</em><br />Make sure the table doesn\'t already exist. Refresh this page to try again'));
		}
		else
		{
			echo $success;
			echo 'Inserting record data...';
			
			$sql = 'INSERT INTO `' . UO_TABLE . '` (`id`, `online`) VALUES(\'uo_record:0\', -1)';
			
			$result = mysql_query($sql);	
			
			if(!$result)
			{
					echo $fail;
					echo(sprintf($sql_error, mysql_error()));
					echo(sprintf($tip, 'Check your <em>$db</em> settings in <em>online.php</em><br />Refresh this page to try again'));
			}
			else
			{
				echo $success;
				echo(sprintf($continue, 3));
			}
			
		}
		
	}
	
	if($install_step == 3)
	{
	
		?>
			Add the following PHP code to your webpages:<br />
			<?
				echo(sprintf($code, nl2br(str_replace('users-online/online.php', '<em>users-online/online.php</em>', htmlspecialchars("<?php\ninclude_once('users-online/online.php');\nlist(\$online, \$record) = users_online();\n?>\n\n<p>There are currently <?=\$online?> users online. The most ever online is <?=\$record?></p>
				")))));
				?>
				<p><strong>Change</strong> <em>users-online/online.php</em> to the location of the online.php file on your server if you haven't just uploaded the users-online folder.</p>
				<p><strong>Installation complete!</strong></p>
				<p><strong>Please delete this file (install.php) from your server</strong></p>
			</code>
				
		<?
	
	}
	
	
?>
</div>
</body>
</html>
<?
ob_end_flush();
?>
		
Return current item: Users online