<?php
@session_start();
$pagename = basename( $_SERVER[ 'SCRIPT_FILENAME' ] );
$pg = 'index';

require( 'includes/mysql_connect.php' );
require( 'includes/text_functions.php' );
require( 'includes/functions.php' );

$show = $_GET[ 'show' ];
if ( $show == "top100" ) {
	$_SESSION[ 'top100' ] = 1;
	$number_of_posts = 50;
	$start = 50;
	$limit = 50;
	$title = 'Top 100 Online Browser Games';
} else if ( $show == "top50" ) {
	$number_of_posts = 50;
	$title = 'Top 50 Online Browser Games';
	$start = 0;
	$limit = 50;
} else {
	$number_of_posts = 20;
	$title = 'Online browser games | Find the best rpg games here';
}

$_SESSION[ 'posts_start' ] = $_SESSION[ 'mstart' ] ? $_SESSION[ 'posts_start' ] : $number_of_posts;

$special = $_GET[ 'special' ];


if ( $_SESSION[ 'top100' ] == 1 ) {
	$start = 50;
	$limit = 50;
	unset( $_SESSION[ 'top100' ] );
}

//unsubscribe function
if ( $_GET[ 'u' ] == 1 ) {
	$unsub = clean( $_GET[ 'p' ] );
	$site_id = clean( $_GET[ 'site_id' ] );
	$cc = mysql_query( "SELECT `site_id`,`email`,`noemail`,`title` FROM `sites` WHERE `noemail_update`='$unsub' AND `site_id`='$site_id'" );
	$store = mysql_fetch_array( $cc );
	if ( $store[ 'email' ] ) {
		if ( $store[ 'noemail' ] == 1 ) {
			echo "<SCRIPT>alert('This account is already unsubscribed!');</SCRIPT>";
		} else {
			if ( $_GET[ 'store1' ] == 1 ) {
				mysql_query( "UPDATE `sites` SET `noemail`='1' WHERE `noemail_update`='$unsub' AND `site_id`='$site_id'" );
				echo "<SCRIPT>alert('Succesfully Unsubscribed!');</SCRIPT>";
			} else {

				echo "<SCRIPT>var answer = confirm('Are you sure you want to leave are SUPER-WORTHY INFREQUENT Newsletter?');
				if(answer){
					window.location = '?u=1&p=" . $unsub . "&site_id=" . $site_id . "&store1=1';
				}
				else{
					alert('Most excellent choice! Enjoy!');
				}</SCRIPT>";

				//echo '<br><br><center>Do you wish to unsubscribe the account '.apo_db_keimeno($store['title']).' ('.$store['email'].') from our newsletter ?<br><br><a href="/?u=1&p='.$unsub.'&site_id='.$site_id.'&store1=1">Yes</a> | <a href="/">No</a></center>';
				//die();
			}
		}
	}
}

?>
<!DOCTYPE HTML>
<html>

<head>
	<!-- Global site tag (gtag.js) - Google Analytics -->
	<script async src="https://www.googletagmanager.com/gtag/js?id=UA-1338068-2"></script>
	<script>
		window.dataLayer = window.dataLayer || [];

		function gtag() {
			dataLayer.push( arguments );
		}
		gtag( 'js', new Date() );

		gtag( 'config', 'UA-1338068-2' );
	</script>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<link rel="icon" href="favicon.ico" type="image/x-icon"/>
	<link rel="shortcut icon" href="favicon.ico" type="image/x-icon"/>
	<title>
		<?php echo $title; ?>
	</title>
	<meta name="keywords" content="online browser games, browser games, browser rpg, browser rpg games, vampire browser game, browser mmorpg, browser mmo, browser strategy games, browser mafia games"/>
	<meta name="description" content="Find Online browser games, RPG , MMORPG, MMO, Strategy, Simulation, Sports, space vampire browser games"/>
	<meta name="author" content="OMGSPIDER.com"/>
	<meta name="copyright" content="2007-2018 by OMGSPIDER.com free online browser rpg games"/>
	<link href="css/full.css?v=2" rel="stylesheet" type="text/css"/>
	<script async src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
</head>

<body bgcolor="#dddddd" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" style="padding-right:0px;padding-left:0px;font-size:9pt;padding-bottom:0px;margin:0px;color:#000000;padding-top:0px;font-family:arial,helvetica;" width="100%" valign="top" cellpadding="0" cellspacing="0">
	<table align="center" width="728" border="0" cellpadding="0" cellspacing="0">
		<tr>
			<td align="left" bgcolor="#dddddd">
				<?php require('includes/leaderboard.php'); 
?>
			</td>
		</tr>
		<tr>
			<td align="center">
				<table align="center" border="0" cellpadding="0" cellspacing="0" width="728">
					<tr>
						<td colspan="5" align="center" bgcolor="#182620">
							<?php require_once('includes/top_menu.php'); ?>
						</td>
					</tr>
					<tr>
						<td colspan="5" align="center" bgcolor="#aca0a0">
							<table height="56">
								<tr>
									<td align="right">
										<a href="https://www.omgspider.com/">
											<IMG src="img/logo.gif" width="296" height="56" border="0" alt="Online Browser Games"/>
										</a>
									</td>
									<td align="left">
										<table cellpadding="0" height="56" cellspacing="0" border="0" valign="middle">
											<tr>
												<td align="center">
													<h2>Online Browser RPG Games</h2>
												</td>
											</tr>
											<tr>
												<td align="left">
													<?php include('includes/search.html'); ?>
												</td>
											</tr>
										</table>
									</td>
								</tr>
							</table>
						</td>
					</tr>
					<tr>
						<td width="130" valign="top">
							<table border="0" width="100%" align="center" cellpadding="0" cellspacing="0" valign="top">
								<tr>
									<td align="left" bgcolor="#aca0a0">
										<? include('includes/menu.php'); ?>
									</td>
								</tr>
								<tr>
									<td>&nbsp;</td>
								</tr>
								<tr>
									<td align="center">
										<?php require('includes/square.php'); ?>
									</td>

								</tr>
								<tr>
									<td align="center"><br/>
										<?php




										//REgister Vote
										/*
										if($_SERVER['REMOTE_ADDR'] == '88.218.9.60'){
											print_r($_POST);
										}
										*/
										$vote = $_POST[ 'voteimg_x' ];
										if ( $vote ) {
											sleep( 1 );
											if ( $_POST[ 'myvote' ] == session_id() ) {
												$vid = clean( $_POST[ 'vid' ] );
												$user_id = clean( $_POST[ 'user_id' ] );
												$confirmation = clean( $_POST[ 'confimation' ] );
												$mini = $_REQUEST[ 'mini' ];

												if ( $mini == 1 ) {
													$table = 'mini_voting';
													$column = 'mini_votes';
												} else {
													$table = 'voting';
													$column = 'votes';
												}

												if ( $confirmation == 1 ) {
													$vote_echo = '<tr>
<td colspan="3" align="center" class="standard" bgcolor="#ffcc00"><strong>You have already voted once in the past 24 hours!<br />You can vote one time per 24hours. Try again later.</strong></td></tr>';
												} else {

													$entry = $_GET[ 'entry' ];
													$validity = $_POST[ 'validity' ];
													$entry_code = $entry + 1;
													$valid_code = md5( $entry_code );

													if ( $validity == $valid_code ) {
														$ttime = time() - 1;
														if ( $_POST[ 'ab' ] > 0 ) {
															if ( $_POST[ 'ab' ] < $ttime ) {
																$sql = mysql_query( "SELECT site_id,counted from `" . $table . "` where `vid`='$vid' and `confirmation`='$confirmation'" );
																if ( $sql && $rese = mysql_fetch_object( $sql ) ) {
																	$site_id = $rese->site_id;
																	$counted = $rese->counted;
																}

																if ( $site_id == 39 ) {
																	if ( $_SESSION[ 'string' ] == md5( $_POST[ 'pass' ] ) ) {} else {
																		$counted = 1;
																	}
																}

																$ef = $_POST[ 'ef' ];
																$ik = $_POST[ 'ik' ];

																if ( md5( $ef ) != $ik ) {
																	$counted = 1;
																}

																if ( $counted == "0" ) {
																	$updcount = mysql_query( "UPDATE `" . $table . "` SET `counted`='1' where `vid`='$vid'" );



																	if ( $updcount ) {
																		$vote_counted = mysql_query( "UPDATE `sites` SET `" . $column . "`=" . $column . "+1 where `site_id`='$site_id'" );



																		//reward voting
																		$sql_reward = mysql_query( "SELECT url,title from `sites` where `site_id`='$site_id'" );
																		if ( $sql_reward && $rese_reward = mysql_fetch_object( $sql_reward ) ) {
																			$base_url = $rese_reward->url;
																			$vote_gname = $rese_reward->title;
																		}

																		$vote_echo = '<tr>
<td colspan="3" align="center" class="standard" bgcolor="#ffcc00"><strong>You have successfully voted +1 Vote for ' . $vote_gname . '!</strong></td></tr>';

																		if ( $user_id && $mini != 1 ) {


																			$url = parse_url_domain( $base_url );
																			if ( preg_match( '/https/i', $base_url ) ) {
																				$url = 'https://' . $url . '/omgspider.php';
																			} else {
																				$url = 'http://' . $url . '/omgspider.php';
																			}
																			$ch_initial = curl_init( $url );
																			curl_setopt( $ch_initial, CURLOPT_POST, 1 );
																			curl_setopt( $ch_initial, CURLOPT_POSTFIELDS, "user_id=" . $user_id . "&unique_pass=" . $vid );
																			curl_exec( $ch_initial );
																			curl_close( $ch_initial );

																		}


																	}
																}
															}
														}
													} else {}

												}

											}
										}


										require( 'includes/mini_vote.php' );
										?>
									</td>
								</tr>
								<tr>
									<td align="center"><br/>
										<?php

										require( 'includes/latest.php' );
										?>
									</td>
								</tr>
							</table>
						</td>
						<td valign="top" width="468">
							<table border="0" align="center" valign="top" width="468" bgcolor="#aca0a0">
								<tr>
									<td align="center" valign="top" bgcolor="#aca0a0">
										<IMG src="img/hrbar2.gif"/>
									</td>
								</tr>
								<tr>
									<td bgcolor="#FFFFFF" align="center">
										<div ID="showscreenshot">
											<table border="0" align="center" cellspacing="0" width="468">
												<?php

												if ( $vote_echo ) {
													echo $vote_echo;

												}

												?>
												<tr>
													<td colspan="3" align="center" class="standard"><strong>Online Multiplayer Games Search Engine</strong>
													</td>
												</tr>
												<tr>
													<td valign="top" colspan="3" class="standard" align="left">
														<?php


														echo '<IMG src="img/topgames.gif" alt="TopBrowser Games"/>';


														$fmachine_time = gmdate( 'Y-m-d H:i:s', strtotime( '+9 hours' ) );

														?>
													</td>
												</tr>
												<?php



												$sqlm = mysql_query( "select title,month from `sites` right join `gmonth` on `gmonth`.`site_id`=`sites`.`site_id` order by `gmonth`.`machine_time` desc limit 0,1" );
												if ( $sqlm && $rese = mysql_fetch_object( $sqlm ) ) {
													$title = $rese->title;
													$month = $rese->month;
												}

												?>
												<tr>
													<td colspan="3" class="thank_you" align="center">
														<?php if($special == 'mini'){
	echo '<span class="standard">The mini challenge is on!</span>';
}
else if($special == "latest"){
	echo '<span class="standard">Latest games submitted in OMGSPIDER.com</span>';
}
else{
	echo $month.' Winner: <a href="gmonth.php" class="links">'.$title.'</a>';
}	
	?>
													</td>
												</tr>
												<tr>
													<td class="tabletitle" align="center" width="18">#</td>
													<td class="tabletitle" align="left">
														<?php if($special == "mini"){
	echo 'MINI OMGSPIDER TOPLIST';
}
else{
	echo 'Best MMORPG / Browser Games';
}
?>
													</td>
													<td class="tabletitle" align="center">Votes</td>
												</tr>
												<tr>
													<td align="center" colspan="3">
														<div id="posts-container">
															<div id="posts">
																<?php

																if ( $_GET[ 'start' ] > 0 ) {
																	$start = clean( $_GET[ 'start' ] );
																} else {
																	if ( !( isset( $start ) ) ) {
																		$start = 0;
																	}
																}
																if ( !( isset( $limit ) ) ) {
																	$limit = 20;
																}
																if ( $start > 2000 ) {
																	$start = 2000;
																}
																$next = $start + $limit;

																if ( $special == "mini" ) {
																	$sql = mysql_query( "SELECT SQL_NO_CACHE site_id, url, title, short_desc, if((sub_expiration > now()),1,0) as show_banner, banner, mini_votes as votes, review_id from `sites` where `allowvoting`='1' ORDER BY mini_votes DESC limit $start,$limit" );
																} else if ( $special == "premium" ) {
																	$sql = mysql_query( "SELECT SQL_NO_CACHE site_id, url, title, short_desc, if((sub_expiration > now()),1,0) as show_banner, banner, votes, review_id from `sites` where `allowvoting`='1' and `sub_expiration`>now() ORDER BY `votes` DESC limit $start,$limit" );
																} else if ( $special == "latest" ) {
																	$sql = mysql_query( "SELECT SQL_NO_CACHE site_id, url, title, short_desc, if((sub_expiration > now()),1,0) as show_banner, banner, votes, review_id from `sites` where `allowvoting`='1' ORDER BY `site_id` DESC, `votes` DESC limit $start,$limit" );
																} else {
																	$sql = mysql_query( "SELECT SQL_NO_CACHE site_id, url, title, short_desc, if((sub_expiration > now()),1,0) as show_banner, banner, votes, review_id from `sites` where `allowvoting`='1' ORDER BY votes DESC limit $start,$limit" );
																}

																$add = 1;
																while ( $row = mysql_fetch_assoc( $sql ) ) {

																	$row[ 'ID' ] = $start + $add;

																	$row[ 'title' ] = apo_db_keimeno( $row[ 'title' ] );
																	$row[ 'short_desc' ] = apo_db_keimeno( $row[ 'short_desc' ] );

																	$position = $row[ 'ID' ];



																	if ( $row[ 'show_banner' ] == 1 ) {
																		$banner = 1;
																		$row[ 'banner' ] = '<p style="margin-top:5px;"><a href="' . $row[ 'url' ] . '" target="_blank" ><img src="ads/banners/' . $row[ 'banner' ] . '" width="445" height="57" border="0" /></a></p>';
																	} else {
																		$banner = 0;
																	}


																	if ( $add == 6 || $add == 14 ) {
																		echo '<div class="post" style="display: block; ">
			<span class="srankings"><IMG src="img/star.gif" border="0"> Premium Browser Game</span><p style="margin-top:5px;">';

																		include( 'includes/rectop.php' );

																		echo '</p></div>';
																	}


																	$row_echo = '<div class="post" id="post-1" style="display: block; ">
    	<span class="srankings">' . $position . '</span> <a href="' . $row[ 'url' ] . '" target="_blank" class="post-title">' . $row[ 'title' ] . '</a><span style="position:relative; float:right;text-align:right;" class="votes">' . $row[ 'votes' ] . '</span>';

																	if ( $banner == 1 ) {
																		$row_echo .= $row[ 'banner' ];
																	}

																	$row_echo .= '<p class="post-content">' . $row[ 'short_desc' ];

																	if ( $row[ 'review_id' ] > 0 ) {
																		$row_echo .= '<br><a href="reviews.php?show=' . $row[ 'review_id' ] . '" class="post-more">(Read Review)</a>';
																	}

																	$row_echo .= '</p></div>';

																	echo $row_echo;

																	$add++;
																}
																?>
															</div>
															<div id="load-more"><a href="/?start=<?php echo $next; ?>&special=<?php echo $special; ?>" class="post-title">Click here to load more top games !</a>
															</div>
														</div>
													</td>
												</tr>
											</table>
										</div>
										<?php require('includes/footer.php'); ?>