In lots of games without validations, many users will have bots training and doing crimes for them, so I have coded a validation mod.
Step 1 - MySQL Fields:
In the users table, create the following fields:
valtries (int) 11
validation (int) 11
NOTE: Remember to add these 2 fields to the register.php when inserting new users.
Step 2 - The Files:
validate.php
-------------
<?php
session_start();
require "global_func.php";
if($_SESSION['loggedin']==0) { header("Location: login.php");exit; }
$userid=$_SESSION['userid'];
require "header.php";
$h = new headers;
$h->startheaders();
include "mysql.php";
global $c;
$is=mysql_query("SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid WHERE u.userid=$userid",$c) or die(mysql_error());
$ir=mysql_fetch_array($is);
check_level();
$fm=money_formatter($ir['money']);
$cm=money_formatter($ir['crystals'],'');
$lv=date('F j, Y, g:i a',$ir['laston']);
$h->userdata($ir,$lv,$fm,$cm);
$h->menuarea();
if(!$_POST['action'])
{
$hi=rand(111111,999999);
$rand=rand(1,9);
$p=$_GET['p'];
?>
</pre>
<table border="1" width="50%"> [img=img.php]
(Please enter the 5 digit number you see above you into this box to verify yourself.)</table>
<br><?<br>}<br>else if($_POST['action'] == "go")<br>{<br>$_POST['choice']=abs((int)$_POST['choice']);<br>if($_POST['choice'] != $_SESSION['num'])<br>{<br>mysql_query("UPDATE users SET valtries=valtries-1 WHERE userid=$userid",$c);<br>if($ir['valtries'] == 0)<br>{<br>$jail=rand(100,200);<br>mysql_query("UPDATE users SET valtries='10' WHERE userid=$userid",$c);<br>mysql_query("UPDATE users SET jailreason='Failed to validate 10 times',jail=$jail WHERE userid=$userid",$c);<br>print "You have been sent to jail for $jail minutes for failing to validate within 10 tries.";<br>}<br>die("You have {$ir['valtries']} tries left to choose the correct validation number. If you fail to do so within 10, you will be sent to jail!<br>> [url='validate.php']Back[/url]");<br>}<br>else if($_SESSION['num'] == $_POST['choice'])<br>{<br>mysql_query("UPDATE users SET validation=20,valtries=10 WHERE userid=$userid",$c);<br>print "You successfully validated, now bringing you back to what you were doing.";<br>if($_POST['page'])<br>{<br>?><br><br><?<br>}<br>}<br>}<br>$h->endpage();<br
img.php
--------
<?php
session_start();
require "global_func.php";
require "mysql.php";
global $c;
if($_SESSION['loggedin']==0) { header("Location: login.php");exit; }
if(!$_SESSION['userid']) { header ("Location: login.php"); exit; }
$userid=$_SESSION['userid'];
$is=mysql_query("SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid WHERE u.userid=$userid",$c) or die(mysql_error());
$ir=mysql_fetch_array($is);
check_level();
$num=rand(11111,99999);
$_SESSION['num']=$num;
header("Content-Type: image/png");
$img_handle = imageCreateFromPNG("background2.png");
$color = ImageColorAllocate ($img_handle, 0, 0, 0);
ImageString ($img_handle, 5, 12, 9,"$num", $color);
ImagePng ($img_handle);
ImageDestroy ($img_handle);
?>
Step 3 - Editing Cron Jobs:
Locate "cron_hp.php" and add the following line:
mysql_query("UPDATE users SET validation=validation-1 WHERE validation > 0",$c);
Step 4 - Redirecting to validate.php:
In the files you like the users to validate before using (ie: gym.php, docrime.php), locate the line "$lv=date('F j, Y, g:i a',$ir['laston']);" and directly underneath, paste this:
if(!$ir['validation'])
{
?>
<?
}
Any bugs/suggestions? Post it here.