Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

[Release] PHP Cash Shop NX Code Generator (Per Day)

Status
Not open for further replies.
Initiate Mage
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:

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:
Experienced Elementalist
Joined
Apr 13, 2008
Messages
298
Reaction score
1
GJ aeronux =)

It works on your test page, it's not a phail o.o
 
Initiate Mage
Joined
Jul 2, 2008
Messages
16
Reaction score
0
GJ aeronux =)

It works on your test page, it's not a phail o.o

Haha, yeah, I own that domain (phail.net), so I use it for little projects and miscellaneous things. But thanks ;)
 
Elite Diviner
Joined
Feb 28, 2007
Messages
446
Reaction score
4
I don't see any mysql_real_escape_string's. Tisk Tisk.
 
Initiate Mage
Joined
Jul 2, 2008
Messages
16
Reaction score
0
I don't see any mysql_real_escape_string's. Tisk Tisk.

And where would you suppose I put them since my script doesn't collect any actual input information from the user? ;)
 
Junior Spellweaver
Joined
Feb 24, 2007
Messages
189
Reaction score
1
Antv this is for use inside your control panel. it never collected data from the user because he has it setup inside his control panel. Therefor he does not need to escape and strings.
 
Initiate Mage
Joined
Nov 15, 2006
Messages
40
Reaction score
0
How could you make this for let's say 4 minutes. I don't want it each day, Could you tell me how to make it for 4 min? I really appriciate if you could give it a try.
 
Initiate Mage
Joined
Jun 30, 2008
Messages
46
Reaction score
0
If i click Generate 20k nx i get this:
Incorrect integer value: '' for column 'ID' at row 1
 
Initiate Mage
Joined
Jul 2, 2008
Messages
16
Reaction score
0
How could you make this for let's say 4 minutes. I don't want it each day, Could you tell me how to make it for 4 min? I really appriciate if you could give it a try.

It would be kinda complicated to do that, because it'd require the database table be modified as well as the script... But, I'll work on it, and see if I can't get it going for you. :]

If i click Generate 20k nx i get this:
Incorrect integer value: '' for column 'ID' at row 1

Is that error from my test page or from your server?
 
Initiate Mage
Joined
Jun 30, 2008
Messages
46
Reaction score
0
Guys,, i get this error:
Incorrect integer value: '' for column 'ID' at row 1
 
Junior Spellweaver
Joined
May 5, 2007
Messages
165
Reaction score
0
Find this line:
mysql_query("INSERT INTO `nxcode_track` (ID,IP,Day) VALUES ('','$IP',".date("j").")") or die(mysql_error());

And try to replace it with this:

mysql_query("INSERT INTO `nxcode_track` (ID,IP,Day) VALUES (NULL,'$IP',".date("j").")") or die(mysql_error());
 
Initiate Mage
Joined
Jul 2, 2008
Messages
16
Reaction score
0
Guys,, i get this error:
Incorrect integer value: '' for column 'ID' at row 1

Once again, is that error from your own installation on your private server or on my test page? Did you setup the script properly? Give me some information here, or I can't really help you.

Find this line:
mysql_query("INSERT INTO `nxcode_track` (ID,IP,Day) VALUES ('','$IP',".date("j").")") or die(mysql_error());

And try to replace it with this:

mysql_query("INSERT INTO `nxcode_track` (ID,IP,Day) VALUES (NULL,'$IP',".date("j").")") or die(mysql_error());

I suppose you could try that, but in all the times I've done things with PHP and MySQL (which is a lot) I've never had to add NULL in there... But maybe it'll work for you.
 
Initiate Mage
Joined
Jun 30, 2008
Messages
46
Reaction score
0
Oh sorry, didnt saw you quoted me :)
Uhm, its from my server. uhm checkout: ( no advertisements )
 
Junior Spellweaver
Joined
May 5, 2007
Messages
165
Reaction score
0
Once again, is that error from your own installation on your private server or on my test page? Did you setup the script properly? Give me some information here, or I can't really help you.



I suppose you could try that, but in all the times I've done things with PHP and MySQL (which is a lot) I've never had to add NULL in there... But maybe it'll work for you.

Well if you make it NULL, it will follow the auto increment rule and '' is not an integer xP
 
Initiate Mage
Joined
Jun 30, 2008
Messages
46
Reaction score
0
Thnx alot i fixed already,,
Thnx Zekesamaz and thnx aeronux for releasing!
 
Initiate Mage
Joined
Jul 2, 2008
Messages
16
Reaction score
0
Well if you make it NULL, it will follow the auto increment rule and '' is not an integer xP

I've just never had to do that before though (usually it just follows the auto-increment rule anyway). But thanks for letting me know :)
 
Status
Not open for further replies.
Back
Top