Location: PHPKode > scripts > Browzin'! > browzin/browzin.php
<?php
/*********************************************************
*             Browzin'! Version 1.01 MySQL               *
*             Author: Martin Klavon                      *
*             URL: http://members.lycos.co.uk/klav       *
*********************************************************/

/*********************************************************
                    BROWZIN'! SETTINGS
*********************************************************/

// Set MySQL database variables
$bz_db_host = "";
$bz_db_name = "";
$bz_db_user = "";
$bz_db_pass = "";

// Enter the location of your browzin'! PHP script (add a forward slash if it resides in your root directory)
$bz_path = "/path/to/browzin/"; // << Include a forward slash at the end if you specify a path

// Set session timeout limit in minutes
$bz_sess_timeout = 3;

// Should the who's online link open in a new window? Type Yes or No inside the quotes
$bz_browser_window = "Yes";

// Show IP address? Type Yes or No inside the quotes
$bz_show_ip = "No";

// Show page being viewed? Type Yes or No inside the quotes
$bz_show_page = "Yes";

// Time (in seconds) offset from server?
$bz_time_offset = 0; // << Add 0 if you do not want to change the time
$bz_add_sub = "+"; // << Put + for adding and - for subtracting

// Set default font style
$bz_font_style = "font-family: verdana; font-size: 9pt; color: #000000";

// Set table header font style
$bz_h_font_style = "font-family: verdana; font-size: 9pt; color: #FFFFFF";

// Set default table bg, header and border color
$bz_bgcolor = "#FFFFFF";
$bz_bordercolor = "#990000";
$bz_headercolor = "#CC3333";


/*********************************************************
                DO NOT EDIT BELOW THIS LINE
*********************************************************/


// Setup variables for use in the script
$bz_sess_timeout = (double)$bz_sess_timeout;
$bz_seconds = $bz_sess_timeout * 60;
$bz_time_offset = (double)$bz_time_offset;
if($bz_add_sub == "+" && $bz_time_offset != 0) {
 $bz_date = time()+$bz_time_offset;
}
elseif($add_sub == "-" && $bz_time_offset != 0) {
 $bz_date = time()-$bz_time_offset;
}
else {
 $bz_date = time();
}
$bz_show_ip = strtoupper($bz_show_ip);
$bz_show_page = strtoupper($bz_show_page);
$bz_browser_window = strtoupper($bz_browser_window);

// Determine IP address
if($HTTP_SERVER_VARS['HTTP_X_FORWARDED_FOR'])
$bz_ip = $HTTP_SERVER_VARS['HTTP_X_FORWARDED_FOR'];
else
$bz_ip = $HTTP_SERVER_VARS['REMOTE_ADDR'];

// Connect to the database
$bz_db_connect = @mysql_connect($bz_db_host, $bz_db_user, $bz_db_pass) or die(mysql_error());
if(!empty($bz_db_name)) {
 $bz_db_select = @mysql_select_db($bz_db_name);
 if(!$bz_db_select) {
  echo("Could not select database $bz_db_name. Please make sure you entered a valid database name.");
  exit;
 }
}

// Delete entries that are older than the time set in $bz_sess_timeout
$bz_delete_query = "DELETE FROM browzin WHERE date < $bz_date";
$bz_delete = @mysql_query($bz_delete_query) or die(mysql_error());

$bz_query = "SELECT * FROM browzin WHERE ip = '$bz_ip'";
$bz_result = @mysql_query($bz_query) or die(mysql_error());

if(mysql_num_rows($bz_result) > 0) {
 while($bz_row = mysql_fetch_array($bz_result)) {
  if($bz_row['ip'] == $bz_ip) {
   $bz_update_query = "UPDATE browzin SET date = $bz_date+$bz_seconds, page = '".$HTTP_SERVER_VARS['SCRIPT_NAME']."' WHERE ip = '".$bz_ip."'";
   $bz_update = @mysql_query($bz_update_query) or die(mysql_error());
  }
  else {
   $bz_insert_query = "INSERT INTO browzin VALUES($bz_date+$bz_seconds, '".$bz_ip."', '".$HTTP_SERVER_VARS['SCRIPT_NAME']."', 0)";
   $bz_insert = @mysql_query($bz_insert_query) or die(mysql_error());
  }
 }
}
else {
 $bz_insert_query = "INSERT INTO browzin VALUES($bz_date+$bz_seconds, '".$bz_ip."', '".$HTTP_SERVER_VARS['SCRIPT_NAME']."', 0)";
 $bz_insert = @mysql_query($bz_insert_query) or die(mysql_error());
}

if($HTTP_GET_VARS['view'] == "browzin") {
 $bz_query = "SELECT * FROM browzin order by date, b_id asc";
 $bz_result = @mysql_query($bz_query) or die(mysql_error());
 echo("<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" summary=\"Who's Browzin' the site?\">\n<tr><td>");
 echo("<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">\n<tr><td bgcolor=\"$bz_bordercolor\">");
 if($bz_show_ip == "YES" && $bz_show_page == "YES") {
  echo("<table cellpadding=\"2\" cellspacing=\"1\" border=\"0\">\n<tr><td bgcolor=\"$bz_headercolor\" style=\"$bz_h_font_style\"><b>#</b></td>\n<td bgcolor=\"$bz_headercolor\" style=\"$bz_h_font_style\"><b>IP Address</b></td>\n<td bgcolor=\"$bz_headercolor\" style=\"$bz_h_font_style\"><b>Domain Name/Host</b></td>\n<td bgcolor=\"$bz_headercolor\" style=\"$bz_h_font_style\"><b>Page</b></td>\n<td bgcolor=\"$bz_headercolor\" style=\"$bz_h_font_style\"><b>Time Online</b></td>\n</tr>");
 }
 elseif($bz_show_ip == "YES" && $bz_show_page == "NO") {
  echo("<table cellpadding=\"2\" cellspacing=\"1\" border=\"0\">\n<tr><td bgcolor=\"$bz_headercolor\" style=\"$bz_h_font_style\"><b>#</b></td>\n<td bgcolor=\"$bz_headercolor\" style=\"$bz_h_font_style\"><b>IP Address</b></td>\n<td bgcolor=\"$bz_headercolor\" style=\"$bz_h_font_style\"><b>Domain Name/Host</b></td>\n<td bgcolor=\"$bz_headercolor\" style=\"$bz_h_font_style\"><b>Time Online</b></td>\n</tr>");
 }
 elseif($bz_show_ip == "NO" && $bz_show_page == "YES") {
  echo("<table cellpadding=\"2\" cellspacing=\"1\" border=\"0\">\n<tr><td bgcolor=\"$bz_headercolor\" style=\"$bz_h_font_style\"><b>#</b></td>\n<td bgcolor=\"$bz_headercolor\" style=\"$bz_h_font_style\"><b>Domain Name/Host</b></td>\n<td bgcolor=\"$bz_headercolor\" style=\"$bz_h_font_style\"><b>Page</b></td>\n<td bgcolor=\"$bz_headercolor\" style=\"$bz_h_font_style\"><b>Time Online</b></td>\n</tr>");
 }
 else {
  echo("<table cellpadding=\"2\" cellspacing=\"1\" border=\"0\">\n<tr><td bgcolor=\"$bz_headercolor\" style=\"$bz_h_font_style\"><b>#</b></td>\n<td bgcolor=\"$bz_headercolor\" style=\"$bz_h_font_style\"><b>Domain Name/Host</b></td>\n<td bgcolor=\"$bz_headercolor\" style=\"$bz_h_font_style\"><b>Time Online</b></td>\n</tr>");
 }
 $i = 1;
 while($bz_row = mysql_fetch_array($bz_result)) {
  $bz_host_address = @gethostbyaddr($bz_row['ip']);
  if(!$bz_host_address) {
   $bz_host_address = $bz_ip." (IP)";
  }
  $bz_time_view = (double)$bz_row['date'];
  if($bz_show_ip == "YES" && $bz_show_page == "YES") {
   echo("<tr>\n<td bgcolor=\"$bz_bgcolor\" style=\"".$bz_font_style."\">$i</td>\n<td bgcolor=\"$bz_bgcolor\" style=\"".$bz_font_style."\">".$bz_row['ip']."</td>\n<td bgcolor=\"$bz_bgcolor\" style=\"".$bz_font_style."\">$bz_host_address</td>\n<td bgcolor=\"$bz_bgcolor\" style=\"".$bz_font_style."\">".$bz_row['page']."</td>\n<td bgcolor=\"$bz_bgcolor\" style=\"".$bz_font_style."\">".date("H:i - nS M", $bz_time_view)."</td>\n</tr>\n");
  }
  elseif($bz_show_ip == "YES" && $bz_show_page == "NO") {
   echo("<tr>\n<td bgcolor=\"$bz_bgcolor\" style=\"".$bz_font_style."\">$i</td>\n<td bgcolor=\"$bz_bgcolor\" style=\"".$bz_font_style."\">".$bz_row['ip']."</td>\n<td bgcolor=\"$bz_bgcolor\" style=\"".$bz_font_style."\">$bz_host_address</td>\n<td bgcolor=\"$bz_bgcolor\" style=\"".$bz_font_style."\">".date("H:i - jS M", $bz_time_view)."</td>\n</tr>\n");
  }
  elseif($bz_show_ip == "NO" && $bz_show_page == "YES") {
   echo("<tr>\n<td bgcolor=\"$bz_bgcolor\" style=\"".$bz_font_style."\">$i</td>\n<td bgcolor=\"$bz_bgcolor\" style=\"".$bz_font_style."\">$bz_host_address</td>\n<td bgcolor=\"$bz_bgcolor\" style=\"".$bz_font_style."\">".$bz_row['page']."</td>\n<td bgcolor=\"$bz_bgcolor\" style=\"".$bz_font_style."\">".date("H:i - jS M", $bz_time_view)."</td>\n</tr>\n");
  }
  else {
   echo("<tr>\n<td bgcolor=\"$bz_bgcolor\" style=\"".$bz_font_style."\">$i</td>\n<td bgcolor=\"$bz_bgcolor\" style=\"".$bz_font_style."\">$bz_host_address</td>\n<td bgcolor=\"$bz_bgcolor\" style=\"".$bz_font_style."\">".date("H:i - jS M", $bz_time_view)."</td>\n</tr>\n");
  }
  $i++;
 }
 echo("</table>\n</td></tr>\n</table>\n</td></tr>\n<tr><td align=\"center\" style=\"font-size: 8pt; font-family: verdana, arial; color: #000000\">\n<a href=\"http://members.lycos.co.uk/klav\" target=\"_blank\" style=\"font-size: 8pt; font-family: verdana, arial; color: #000000\">Browzin'! V1.01</a> by Martin Klavon\n</td></tr>\n</table>\n");
}
else {
 $bz_query = "SELECT * FROM browzin";
 $bz_result = @mysql_query($bz_query) or die(mysql_error());
 $bz_num_online = mysql_num_rows($bz_result);
 if($bz_browser_window == "YES"){echo("<a href=\"".$bz_path."browzin.php?view=browzin\" target=\"_blank\" style=\"$bz_font_style\">");} else{echo("<a href=\"".$bz_path."browzin.php?view=browzin\" style=\"$bz_font_style\">");}
 if($bz_num_online > 1 || $bz_num_online == 0){echo("There are ");}else{echo("There is ");}if($bz_num_online == 0){echo("no ");}else{echo($bz_num_online." ");}if($bz_num_online > 1 || $bz_num_online == 0){echo("users online");}else{echo("user online");}
 echo("</a>");
}
?>
Return current item: Browzin'!