ok after solving the mktime problem, I used that code to make a new page called jailtimer, This will go on every page where if the user is in jail they aren't allowed to use that feature.
so on the certain pages in the correct position I use the require tool to bring the jailtimer to check if the user is in jail or not. Eventhough this is successful and if they are in jail it shows how long left they have in jail it still shows the data below it...
crimes.php
CODE
<?php
require("jailtimer.php");
echo '<br>';
if (isset($_SESSION['userid'])) {
// this is because i dont like MySQL timestamp i like the UNIX style
function revertcrimetime($str) {
list($date, $time) = explode(' ', $str);
list($year, $month, $day) = explode('-', $date);
list($hour, $minute, $second) = explode(':', $time);
$timestamp = mktime($hour, $minute, $second, $month, $day, $year);
return $timestamp;
}
$q = "SELECT crimetimer FROM login WHERE id='".$_SESSION["userid"]."'";
$r = mysql_query($q);
$v = mysql_fetch_array($r);
$lastActive = revertcrimetime($v['crimetimer']);
if (($lastActive + (1.5*60) - time() > 0)) { // 10*60 = 10 minutes change 10 to 5 if you want 5 min
// session expired send to index
$result = $lastActive + (1.5*60) - time();
echo 'You cannot commit a crime for '.$result.' seconds.';
}else {?>
<form method = "post"
action = "crime.php">
<table border="1" cellspacing="0" bordercolor="#000000"width= "200">
<tr><td colspan="2" bgcolor="#666666" align="center"><b>Crimes</b></td></tr>
<?php
$query ="SELECT id, crime FROM crimes ORDER BY id DESC LIMIT 5";
$result = mysql_query($query);
while ($row = mysql_fetch_array ($result))
{
$id = $row['id'];
$crime = $row['crime'];
echo'
<tr><td width="10">
<input type = "radio"
name = "crimeid"
value = "'.$id.'"></td><td align="right">'.$crime.'</tr>';}?></table>
<center>
<br>
<input type = "submit"
value= "Commit">
</center>
</form>
<? } }
?>
jailtimer.php
[code]
<?
$query = "SELECT username FROM login WHERE id='".$_SESSION["userid"]."'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
$username = $row['username'];
$qu = "SELECT * FROM jail WHERE username = '".$username."'";
$re = mysql_query($qu);
$vu = mysql_fetch_array($re);
if ($vu != 0){
function revertjailtime($str) {
list($date, $time) = explode(' ', $str);
list($year, $month, $day) = explode('-', $date);
list($hour, $minute, $second) = explode(':', $time);
$timestamp = mktime($hour, $minute, $second, $month, $day, $year);
return $timestamp;
}
$q = "SELECT time, length FROM jail WHERE username='".$username."'";
$r = mysql_query($q);
$v = mysql_fetch_array($r);
$length = $v['length'];
$lastActive = revertjailtime($v['time']);
if ($lastActive + $length - time() > 0) {
$result = $lastActive + $length - time();
echo 'You are still in jail for '.$result.' seconds.';
} else {
$delete="DELETE FROM jail WHERE username = '".$username."'";
mysql_query($delete);
}}
?>[code]