Newbie Spellweaver
- Joined
- Jul 2, 2008
- Messages
- 16
- Reaction score
- 0
This script allows you to generate a code for NX in the Cash Shop once per day. One IP address may only generate one code per day. Code is good for 20,000 NX. Script requires a new database table called 'nxcode_track', and setup is provided from within the script.
It has been tested, but please report any errors/bugs/etc to me if you like. Also, you can change the amount of NX by editing the query, and I can also modify it for multiple NX amounts if you're interested.
Also keep in mind that the Cash Shop must be working on your private server with the ability to input NX codes (coupons) for this to function correctly.
Lastly, the script's output is not really styled, so it's up to you to make it match your site if you feel so inclined.
TEST PAGE HERE:
It has been tested, but please report any errors/bugs/etc to me if you like. Also, you can change the amount of NX by editing the query, and I can also modify it for multiple NX amounts if you're interested.
Also keep in mind that the Cash Shop must be working on your private server with the ability to input NX codes (coupons) for this to function correctly.
Lastly, the script's output is not really styled, so it's up to you to make it match your site if you feel so inclined.
TEST PAGE HERE:
You must be registered to see links
PHP:
<?php
/* ----------
WRITTEN BY AERONUX, JULY 2 2008
This script solution uses IP address and a MySQL Day field
to keep track of giving a user free NX every 24 hours by generating
a 15-digit NX code. **However, it will require you make an extra
database table to keep track of the users who got it already.
FOR SETUP, RUN:
http://yourdomain.com/THIS_SCRIPT.php?go=setup
---------- */
/*DATABASE CONFIG: Please fill this out correctly or script will not work. */
$DB_host = "localhost"; //Host; usually localhost
$DB_user = ""; //User
$DB_pass = ""; //Password
$DB_db = ""; // Database name
/*DATABASE CONNECT */
$connect = mysql_connect($DB_host,$DB_user,$DB_pass);
$db = mysql_select_db($DB_db);
extract($_GET); /*So we can use all GET variables without $_GET[] */
$IP = $_SERVER['REMOTE_ADDR'];
/* Check to see if they've gotten their NX for the day */
$chk1 = @mysql_query("SELECT * FROM `nxcode_track` WHERE `ip`='$IP'");
$num = @mysql_num_rows($chk1);
$chk = @mysql_fetch_array($chk1);
$lasttime = $chk["Day"];
if(mysql_error() && $go != "setup")
{
echo "<font style='color:red;'>You must fill in the database information ";
echo "and run the setup page to add a new table to be able to use this script.";
echo "<br><br>After database information is added, <a href='$PHP_SELF?go=setup'>click here to run setup</a>.";
die();
}
if (($num>0) && ($lasttime != date("j"))) /* 24 hours? */
{ $CANGET = true; } // It's been at least 24 hours
else if($num == 0)
{ $CANGET = true; } // Never requested NX
else
{ $CANGET = false; }// Already received
/* FUNCTION FOR GENERATING CODES
BY BAVILO FROM ODINMS.DE FORUMS */
function createNXCode() {
$chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
srand((double)microtime()*1000000);
$i = 0;
$pass = '' ;
while ($i <= 13) {
$num = rand() % 33;
$tmp = substr($chars, $num, 1);
$pass = $pass . $tmp;
$i++;
}
return $pass;
}
/* MAIN PAGES */
switch($go)
{
case "give": /* Give them NX */
if($CANGET == true)
{
//Delete last one(s)
mysql_query("DELETE FROM `nxcode_track` WHERE `IP`='$IP' OR `ID`='$chk[ID]'");
//Insert new one
mysql_query("INSERT INTO `nxcode_track` (ID,IP,Day) VALUES (NULL,'$IP',".date("j").")") or die(mysql_error());
//Generate and give code
$code = createNXCode();
$ins = mysql_query('INSERT INTO nxcode (code, valid, type, item ) VALUES ("'.$code.'", "1", "3", "20000")') or die(mysql_error());
if($ins)
{
echo "Your code is: <font style='font-size:25px;'><b>$code</b></font>";
echo "<br>Write this down, and use this in the Cash Shop!<br>";
echo "(We cannot show you this code again, so please note it!)";
}
else
{
echo "Error generating NX code.";
}
}
else
{
echo "You've already gotten NX today.";
}
break;
case "setup": /* Setup the script for the database */
$set = mysql_query('CREATE TABLE `'.$DB_db.'`.`nxcode_track` (`ID` INT(6) NOT NULL AUTO_INCREMENT, `IP` VARCHAR(15) NOT NULL DEFAULT \'000.000.000.000\', `Day` INT(2) NOT NULL, PRIMARY KEY (`ID`), INDEX (`IP`, `Day`)) ENGINE = MyISAM') or die(mysql_error());
if($set)
echo "Setup complete, you may use the script.";
else
echo "There was an error setting up the database table.";
break;
default: /* Show the form here, etc. */
?>
<form action="<?=$PHP_SELF;?>?go=give" method="POST">
<input type='submit' value='Generate 20,000 NX Code'>
</form>
<?php
break;
}
?>
Last edited: