Jump to content

Session Interference with Cookies


marcus

Recommended Posts

I have this game, that has worked before, with no changes made, the script decides to time out saying

 

This problem can sometimes be caused by disabling or refusing to accept cookies.

 

index.php [this is what holds the game]

 

<?php
session_start();
$need_log=1;
$page = "Games";

include "/home/xxxxx/public_html/global.php";

layout('header');

$cat = protect($_GET['cat']);
$game = protect($_GET['g']);

if($cat){

if(!$game){
echo "<table border=\"0\" cellspacing=\"3\" cellpadding=\"3\" class=\"forum\">\n";
echo "<tr><td colspan=\"3\" align=\"center\" class=\"forum_title\">Games</td></tr>\n";
$sql = "SELECT * FROM `game_types` WHERE `id`='{$cat}'";
$res = mysql_query($sql) or die(mysql_error());
	if(mysql_num_rows($res) == 0){
	echo "<tr><td align=\"center\">Invalid game category</td></tr>\n";
	}else {
	$x=1;
	$raw = mysql_fetch_assoc($res);
	$sql2 = "SELECT * FROM `games` WHERE `cid`='{$cat}'";
	$res2 = mysql_query($sql2) or die(mysql_error());
		if(mysql_num_rows($res2) == 0){
		echo "<tr><td align=\"center\">There are no games in this category</td></td>\n";
		}else {
		echo "<tr>\n";
			while($row = mysql_fetch_assoc($res2)){
			echo "<td align=\"center\" valign=\"top\"><a style=\"text-decoration:none;\" href=\"/games/index.php?cat={$row['cid']}&g={$row['id']}\"><img src=\"/images/games/{$row['image']}\" border=\"0\"><br>{$row['name']}</a></td>\n";
				if($x == 3){
				echo "</tr><tr>\n";
				$x=0;
				}
			$x++;
			}
		echo "</tr>\n";
		}
	}
echo "</table>\n";
}else {
$sql4 = "SELECT * FROM `games` WHERE `id`='{$game}'";
$res4 = mysql_query($sql4) or die(mysql_error());
	if(mysql_num_rows($res4) == 0){
	echo "<h2>This game does not exist!</h2>\n";
	}else {
	$row4 = mysql_fetch_assoc($res4);
		if(file_exists("./includes/{$row4['link']}")){
		include "./includes/" . $row4['link'];
		}else {
		echo "<h2>Game is not available at this moment!</h2>\n";
		}
	}
}
}else {
echo "<center>\n";
$sql3 = "SELECT * FROM `games` ORDER BY RAND() LIMIT 1";
$res3 = mysql_query($sql3) or die(mysql_error());
echo "<h1>Random Game</h1>\n";
$row3 = mysql_fetch_assoc($res3);
echo "<a style=\"text-decoration:none;\" href=\"/games/index.php?cat={$row3['cid']}&g={$row3['id']}\"><img src=\"/images/games/{$row3['image']}\" border=\"0\"><br>{$row3['name']}</a></center>\n";
}

layout('footer');
?>

 

Now the game:

<?php
$need_log=1;

$act = $_GET['act'];
$rps = $_GET['c'];

$bleep = "SELECT * FROM `games` WHERE `id`='1'";
$bleepr = mysql_query($bleep) or die(mysql_error());
$row = mysql_fetch_assoc($bleepr);

$sql2 = "SELECT * FROM `user_games` WHERE `uid`='{$_COOKIE['uid']}' AND `gid`='1'";
$res2 = mysql_query($sql2) or die(mysql_error());

if(mysql_num_rows($res2) == 0){
$sql3 = "INSERT INTO `user_games` (`uid`,`gid`,`amt`) VALUES('{$_COOKIE['uid']}','1','0');";
$res3 = mysql_query($sql3) or die(mysql_error());
}else {
$row2 = mysql_fetch_assoc($res2);
$tf = 3600*24;
$time = time();
$last = $row2['time'];
$go = $time-$last;

	if($go >= $tf){
	$sql4 = "UPDATE `user_games` SET `amt`='0' WHERE `uid`='{$_COOKIE['uid']}'";
	$res4 = mysql_query($sql4) or die(mysql_error());
	header("Location: /games/index.php?cat=1&g=1");
	}
}

$sql6 = "SELECT * FROM `users` WHERE `id`='{$_COOKIE['uid']}'";
$res6 = mysql_query($sql6) or die(mysql_error());
$row4 = mysql_fetch_assoc($res6);

switch($row4['level']){
case 1: $max = "1000"; break;
case 2: $max = "1000"; break;
case 3: $max = "50"; break;
case 4: $max = "50"; break;
case 5: $max = "75"; break;
case 6: $max = "50"; break;
case 7: $max = "0"; break;
}

switch($row4['special']){
case 0: $max = $max; break;
case 1: $max += 25; break;
}

if($row2['amt'] < $max){

if($act == 'play'){

if($rps){
	if(in_array($rps,range('1','3'))){
		if($_SESSION['play']){
		echo "You cannot refresh!\n";
		}else {
		$rand = rand(1,3);
		$_SESSION['play'] = "1";

			if($rand == '1' && $rps == '1'){
			$outcome = "It was a tie between rock! Nobody wins, figures.\n";
			$pic_a = "rps_rock.png";
			$pic_b = "rps_rock.png";
			$winner = "Nobody";
			$loser = "Nobody";
			$win = 0;
			}

			if($rand == '2' && $rps == '1'){
			$outcome = "Paper covers rock! You lose, nice try though.\n";
			$pic_a = "rps_rock.png";
			$pic_b = "rps_paper.png";
			$winner = "Paper";
			$loser = "Rock";
			$win = 0;
			}

			if($rand == '3' && $rps == '1'){
			$outcome = "Rocks beats scissors! You win 250 cP!\n";
			$pic_a = "rps_rock.png";
			$pic_b = "rps_scissors.png";
			$winner = "Rock";
			$loser = "Scissors";
			$win = 250;
			}

			if($rand == '1' && $rps == '2'){
			$outcome = "Paper covers rock! You win 250 cP!\n";
			$pic_a = "rps_paper.png";
			$pic_b = "rps_rock.png";
			$win = 250;
			$winner = "Paper";
			$loser = "Rock";
			}

			if($rand == '2' && $rps == '2'){
			$outcome = "Paper + Paper = More paper! Nobody wins, haha.\n";
			$pic_a = "rps_paper.png";
			$pic_b = "rps_paper.png";
			$win = 0;
			$winner = "Nobody";
			$loser = "Nobody";
			}

			if($rand == '3' && $rps == '2'){
			$outcome = "Scissors shears paper! You failed, denied!\n";
			$pic_a = "rps_paper.png";
			$pic_b = "rps_scissors.png";
			$win = 0;
			$winner = "Scissors";
			$loser = "Paper";
			}

			if($rand == '1' && $rps == '3'){
			$outcome = "Way to have nice scissors smashed! You lose, almost, but not quite.\n";
			$pic_a = "rps_scissors.png";
			$pic_b = "rps_rock.png";
			$win = 0;
			$winner = "Rock";
			$loser = "Scissors";
			}

			if($rand == '2' && $rps == '3'){
			$outcome = "Nice cutting skills! You win 250 cP!\n";
			$pic_a = "rps_scissors.png";
			$pic_b = "rps_paper.png";
			$win = 250;
			$winner = "Scissors";
			$loser = "Paper";
			}

			if($rand == '3' && $rps == '3'){
			$outcome = "Two pointy objects... shouldn't they repel? Your experience is next to nothing.\n";
			$pic_a = "rps_scissors.png";
			$pic_b = "rps_scissors.png";
			$win = 0;
			$winner = "Nobody";
			$loser = "Nobody";
			}

			give_points($_COOKIE['uid'],$win);
				if($max <= 50){
				give_points($_COOKIE['uid'],-5);
				}
			$timeee = time();
			$sql5 = "UPDATE `user_games` SET `amt`=`amt`+1, `time`='$timeee' WHERE `uid`='{$_COOKIE['uid']}' AND `gid`='1'";
			$res5 = mysql_query($sql5) or die(mysql_error());

			echo "<table border=\"0\" cellspacing=\"3\" cellpadding=\"3\" class=\"forum\">\n";
			echo "<tr><td colspan=\"3\" align=\"center\" class=\"forum_title\">Outcome</td></tr>\n";
			echo "<tr><td align=\"right\"><img src=\"/images/games/in/{$pic_a}\" alt=\"\"></td><td align=\"center\">versus</td><td align=\"left\"><img src=\"/images/games/in/{$pic_b}\" alt=\"\"></td></tr>\n";
			echo "<tr><td colspan=\"3\" align=\"center\">{$outcome}</td></tr>\n";
			echo "<tr><td colspan=\"3\" align=\"right\">Winner: <b>{$winner}</b></td></tr>\n";
			echo "<tr><td colspan=\"3\" align=\"right\">Loser: <b>{$loser}</b></td></tr>\n";
			echo "<tr><td colspan=\"3\" align=\"center\"><a href=\"/games/index.php?cat={$row['cid']}&game={$row['id']}\">Play Again?</a></td></tr>\n";
			echo "</table>\n";
		}
	}else {
	echo "Invalid option!\n";
	}
}else {
echo "The game is rock, paper, scissors, you might want to choose one of those!\n";
}

}else {
echo "<table border=\"0\" cellspacing=\"3\" cellpadding=\"3\" class=\"forum\">\n";
echo "<tr><td colspan=\"3\" align=\"center\" class=\"forum_title\">Rock, Paper, Scissors</td></tr>\n";
echo "<tr><td align=\"center\" valign=\"middle\"><a href=\"/games/index.php?cat={$row['cid']}&game={$row['id']}&act=play&c=1\" style=\"text-decoration:none;\"><img src=\"/images/games/in/rps_rock.png\" alt=\"Rock\" border=\"0\"><br>Rock</a></td>\n";
echo "<td align=\"center\" valign=\"middle\"><a href=\"/games/index.php?cat={$row['cid']}&game={$row['id']}&act=play&c=2\" style=\"text-decoration:none;\"><img src=\"/images/games/in/rps_paper.png\" alt=\"Paper\" border=\"0\"><br>Paper</a></td>\n";
echo "<td align=\"center\" valign=\"middle\"><a href=\"/games/index.php?cat={$row['cid']}&game={$row['id']}&act=play&c=3\" style=\"text-decoration:none;\"><img src=\"/images/games/in/rps_scissors.png\" alt=\"Scissors\" border=\"0\"><br>Scissors</a></td>\n";
echo "</tr>\n";
if($max <= 50){
echo "<tr><td colspan=\"3\" align=\"left\">* Costs 5 cP to play</td></tr>\n";
}
echo "</table>\n";
session_destroy();
}

}else {
echo "<table border=\"0\" cellspacing=\"3\" cellpadding=\"3\" class=\"forum\">\n";
echo "<tr><td align=\"center\" class=\"forum_title\">Rock, Paper, Scissors</td></tr>\n";
echo "<tr><td align=\"center\">You have already played the maximum amount within the last 24 hours!</td></tr>\n";
echo "</table>\n";
}

?>

Link to comment
https://forums.phpfreaks.com/topic/77778-session-interference-with-cookies/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.