Jump to content
MakeWebGames

Pre-Registration


H4x0r666

Recommended Posts

pre-register.php

 

<?php
/* 
* Do the connection to the database
* Execute this SQL via phpmyadmin
--
-- Table structure for table `pre_regs`
--

CREATE TABLE IF NOT EXISTS `pre_regs` (
 `id` int(5) NOT NULL AUTO_INCREMENT,
 `ip` varchar(15) NOT NULL,
 `email` varchar(50) NOT NULL,
 `username` varchar(10) NOT NULL,
 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

ALTER TABLE  `pre_regs` ADD  `pass` VARCHAR( 25 ) NOT NULL;

* Upload this script
*/
$gamename = 'change_this_value';

echo "<h3>Pre Register</h3>";
$alreadyExists = mysql_query("SELECT `ip` FROM `pre_regs` WHERE `ip`='{$_SERVER['REMOTE_ADDR']}'");
if(mysql_num_rows($alreadyExists)) {
echo "<i>You have already pre-registered</i>";
exit(); /* Add your footer in the command, maybe $h->endpage() if using mccodes */
}
if(isset($_POST)) {
$user = filter_var($_POST['user'], FILTER_VALIDATE_STRING) ? mysql_real_escape_string(strip_tags($_POST['user'])) : NULL;
$email = filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) ? $_POST['email'] : NULL;
if(!$user OR !$email) {
	echo "Invalid entries...";
}
$emailExists = mysql_query("SELECT `id` FROM `pre_regs` WHERE `email`='{$email}'");
elseif(mysql_num_rows($emailExists)) {
	echo "Email exists...";
}
$userExists = mysql_query("SELECT `id` FROM `pre_regs` WHERE `username`='{$user}'");
elseif(mysql_num_rows($userExists)) {
	echo "Username exists...";
}
elseif(strlen($user) < 3) {
	echo "Username needs to be longer than 3 characters...";
} else {
echo "You have pre-registered. Check your e-mail.";
$password = genRandomString();
mysql_query("INSERT INTO `pre_regs` (`ip`,`email`,`username`,`pass`) VALUES ('{$_SERVER['REMOTE_ADDR']}', '{$email}', '{$user}', '$password')");
$message = "Your pre-register details to {$gamename}\n Username: {$user}\n Password: {$password}\n Thank you for your pre-register.";
$message = wordwrap($message, 70);
mail('{$email}', 'Pre Register: {$gamename}', $message);
}
}
echo "<form action='' method='post'>
		Username: <input type='text' name='user' length='7' maxlength='15' /> <br />
		Email: <input type='text' name='email' length='7' maxlength='50' /> <br />
		<input type='submit' value='Pre Register' />
	  </form>";

function genRandomString() {
/* Source: http://www.lost-in-code.com/programming/php-code/php-random-string-with-numbers-and-letters/ */
   $length = 10;
   $characters = ’0123456789abcdefghijklmnopqrstuvwxyz’;
   $string = ”;    
   for ($p = 0; $p < $length; $p++) {
       $string .= $characters[mt_rand(0, strlen($characters))];
   }
   return $string;
}
?>

That was rushed.... No style added, just plain text.

Staff File

<?php
include_once('sglobals.php');

if($ir['user_level'] < 2) {
echo "403.";
exit($h->endpage());
}

echo "<h3>Importing Pre-Register</h3>";

if($_POST) {
$get = $db->query("SELECT * FROM `pre_regs` ORDER BY `id` ASC");
while($r = $db->fetch_row($get)) {
	$db->query("INSERT INTO `users` (`username`,`userpass`,`level`,`email`,`login_name`) VALUES ('{$r['username']}', '".md5($r['pass'])."', 1, '{$r['email']}', '{$r['username']}')");
	$message = "Your pre-register details to {$set['game_name']}\n Username: {$user}\n Password: {$password}\n WE HAVE OPENED.";
	$message = wordwrap($message, 70);
	mail('{$r['email']}', 'Game Open: {$set['game_name']}', $message);
           }	
}
} else {
echo "<form action='' method='post'>
		<input type='submit' value='OPEN THE GAME' />
	  </form>";
exit($h->endpage());
}
?>

 

Now, open up your database > users > structure > check all > change > edit all the defaults to what ever :)

Note I haven't tested the script, but PM me if there are any issues.

-sniko

Link to comment
Share on other sites

Thanks alot sniko, i hope it works.. this was also a request for all others who needed it so i think you made some others happy to xD

i cant test it right now.. but i will be in the future :) thanks for taking your time to help. i really appreciate it :D

if you made any changes or want to add an example or noob-friendly guide to insert it etc.. please let us know :)

Mvg,

Link to comment
Share on other sites

and to gurpreet and mixmaster, i dont want to de-activate anything

cuz myself wants to be able to get in the game to view things while

building the game up..

and the users must be able to make an account but not able to play so when the game is all ready,

i can mail them or something to let them know (the game is up)

Link to comment
Share on other sites

  • 2 weeks later...

Look at the code there is like curly braces and then code and then the elseif. You gotta either put that code in the IF or the ELSE. It cannot be floating in between them, because then PHP isn't expecting an ELSE.

EDIT: The whole use of ElseIf is not needed. Since all the queries in the IF are based differently, just use IFs.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...