• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[PHP/HTML] Simple web page to create accounts and characters (tfs0.3.6v7)

stratzilla

Narcissus-OTS
Joined
Jan 22, 2013
Messages
38
Reaction score
0
Location
Canada
Here's an incredibly basic website which I'm sure someone more artistic could make prettier. Normally I'd make something more robust and flowery, but in the early stages of server development, I just wanted a simple page to test account and char creation and subsequent logins. This is by no means perfect, but it is functional. This will create a character witth a hometown of Thais; feel free to code other cities, but for mine I only use Thais.

./index.php
PHP:
<!DOCTYPE html>

<?php include("./common/serverinfo.php"); ?>

<html>
	<head>
		<title><?php echo $title; ?></title>
		<meta charset="utf-8" />
	</head>
	<body>
		<a href="./accountcreate.php">Create an Account</a> <br />
		<a href="./charactercreate.php">Create a Character</a> <br />
		<a href="<?php echo $tibiaclient; ?>">Download Client</a>
	</body>
</html>

./accountcreate.php
PHP:
<!DOCTYPE html>

<?php include("./common/serverinfo.php"); ?>

<html>
	<head>
		<title><?php echo $title; ?></title>
		<meta charset="utf-8" />
	</head>
	<body>
		<form action="./accountcreate-submit.php" method="post">
			<legend>Account Number</legend>
				<input type="text" name="acc" size="<?php echo $acclength; ?>" maxlength="<?php echo $acclength; ?>" required="required"/> <br />
			<legend>Password</legend>
				<input type="password" name="pass" size="<?php echo $passmaxlength; ?>" maxlength="<?php echo $passmaxlength; ?>" required="required"/> <br />
			<legend>Confirm Password</legend>
				<input type="password" name="passtwo" size="<?php echo $passmaxlength; ?>" maxlength="<?php echo $passmaxlength; ?>" required="required"/> <br />
			<input type="submit" value="Create Account" />
		</form>
	</body>
</html>

./accountcreate-submit.php
PHP:
<!DOCTYPE html>

<?php include("./common/serverinfo.php"); include("./common/database.php"); ?>

<html>
	<head>
		<title><?php echo $title; ?></title>
		<meta charset="utf-8" />
		<meta http-equiv="refresh" content="3;url=./index.php" />
	</head>
	<body>
		<?php
			//Grabs user-submitted credentials from previous page
			$accountid = mysql_escape_string($_POST["acc"]);
			$password = mysql_escape_string($_POST["pass"]);
			$confirmation = mysql_escape_string($_POST["passtwo"]);
			//Checks if account field contains only numbers
			if (ctype_digit($accountid) == TRUE) {
				//Checks account number length
				if (strlen($accountid) == $acclength) {
					//Checks password length
					if (strlen($password) >= $passminlength) {
						//Insures there is no duplicate database entry for accountid
						$querycheck = $db->query("
							SELECT *
								FROM accounts a
								WHERE a.name = $accountid
							");
						$checkifone = $querycheck->rowCount();
						//If no duplicate entry...
						if ($checkifone == 0) {
							//Confirms if passwords match
							if ($password == $confirmation) {
								$passhash = sha1($password);
								$database = $db->query("
									INSERT INTO accounts
										VALUES (NULL , '$accountid', '$passhash', '65535', '0', '', '1', '0', '0', '1');
								");
								echo "Your account has been successfully created.";
							//If passwords do not match
							} else {
								echo "Your passwords did not match, please try again.";
							}
						//If account number exists already
						} else {
							echo "There is already an account with that name; please choose a different account number.";
						}
					//If password it too short
					} else {
						echo "Your password is too short; please lengthen it to at least six characters.";
					}
				//If account number is too short
				} else {
					echo "Your account number must be six numbers.";
				}
			//If account number contains non-digits
			} else {
				echo "Your account number must only contain numbers";
			}
		?>
	</body>
</html>

./charactercreate.php
PHP:
<!DOCTYPE html>

<?php include("./common/serverinfo.php"); ?>

<html>
	<head>
		<title><?php echo $title; ?></title>
		<meta charset="utf-8" />
	</head>
	<body>
		<form action="./charactercreate-submit.php" method="post">
			<legend>Account Number</legend>
				<input type="text" name="acc" size="<?php echo $acclength; ?>" maxlength="<?php echo $acclength; ?>" required="required"/> <br />
			<legend>Password</legend>
				<input type="password" name="pass" size="<?php echo $passmaxlength; ?>" maxlength="<?php echo $passmaxlength; ?>" required="required"/> <br /> <br />
			<legend>Character Name</legend>
				<input type="text" name="charname" size="<?php echo $charmaxlength; ?>" maxlength="<?php echo $charmaxlength; ?>" required="requireD"/> <br />
			<legend>Gender</legend>
				<input type="radio" name="gender" value="1" checked="checked"/>Male
				<input type="radio" name="gender" value="0"/>Female <br />
			<legend>Vocation</legend>
				<select name="vocation">
					<option value="4">Knight</option>
					<option value="3">Paladin</option>
					<option value="1">Sorcerer</option>
					<option value="2">Druid</option>
				</select> <br /> <br />
			<input type="submit" value="Create Character"/>
		</form>
	</body>
</html>

./charactercreate-submit.php
PHP:
<!DOCTYPE html>

<?php include("./common/serverinfo.php"); include("./common/database.php"); ?>

<html>
	<head>
		<title><?php echo $title; ?></title>
		<meta charset="utf-8" />
		<meta http-equiv="refresh" content="3;url=./index.php" />
	</head>
	<body>
		<?php
			//Grabs user-submitted credentials from previous page
			$accountid = mysql_escape_string($_POST["acc"]);
			$password = mysql_escape_string($_POST["pass"]);
			$passhash = sha1($password);
			$char = mysql_escape_string($_POST["charname"]);
			$gen = $_POST["gender"];
			$voc = $_POST["vocation"];
			//Checks if char string contains non-alphanumeric characters
			if (ctype_alnum($char) == TRUE) {
				//Checks if charname is long enough
				if (strlen($char) >= $charminlength) {
					//Check if account exists
					$queryacccheck = $db->query("
						SELECT *
							FROM accounts a
							WHERE a.name = '$accountid'
					");
					$accountexist = $queryacccheck->rowCount();
					if ($accountexist == 1) {
						//Check if account number and password are correct
						$confirm = $db->query("
							SELECT *
								FROM accounts a
								WHERE a.name = '$accountid'
								AND a.password = '$passhash'
						");
						$conacc = $confirm->rowCount();
						if ($conacc == 1) {
							//Grab accounts.id for the given user for use later
							$accgrab = $db->query("
								SELECT id
									FROM accounts a
									WHERE a.name = '$accountid'
								");
							foreach ($accgrab as $idinfo) {
								$ident = $idinfo["id"];
							}
							//Insures there is no duplicate database entry for character name
							$querycheck = $db->query("
								SELECT *
									FROM players p
									WHERE p.name = '$char'
								");
							$checkifone = $querycheck->rowCount();
							//Check if duplicate entry
							if ($checkifone == 0) {
								//Inserts character into .sql
								$createchar = $db->query("
									INSERT INTO players
										VALUES (NULL , '$char', '0', '1', '$ident', '8', '$voc', '185', '185',
												'4200', '0', '0', '0', '0', '136', '0', '0', '35', '35', '0', '100',
												'3', '32369', '32241', '7', '', '470', '$gen', '1', '1', '1', '0', '0',
												'0', '', '1', '0', '0', '151200000', '2', '100', '100', '100', '100',
												'100', '0', '0', '0', '0', '0', '')
								");
								echo "Character successfully created.";
							//If character already exists
							} else {
								echo "There is a character with this name already. Please choose another name.";
							}
						//If account credentials don't match the database
						} else {
							echo "Your account number and password are not correct, please try again.";
						}
					//If account number doesn't exist
					} else {
						echo "Account does not exist, please make an account before creating a character.";
					}
				//If character name is too short
				} else {
					echo "Character names must be at least four letters long.";
				}
			//If character name contains invalid characters
			} else {
				echo "Your character name contains illegal character.";
			}
		?>
	</body>
</html>

./common/database.php
PHP:
<?php
	$SERVER   = "localhost";
	$USERNAME = ""; //SQL username
	$PASSWORD = ""; //SQL password
	$DATABASE = ""; //Database your OT works with
	$db = new PDO("mysql:dbname={$DATABASE}; host={$SERVER}", $USERNAME, $PASSWORD);
	$db->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
?>

./common/serverinfo.php
PHP:
<?php
	$title = ""; //Server name
	$accminlength = ""; //Account number min length
	$accmaxlength = ""; //Account number max length
	$passminlength = ""; //Password min length
	$passmaxlength = ""; //Password max length
	$charminlength = ""; //Character name min length
	$charmaxlength = ""; //Character name max length
	$tibiaclient = ""; //Location of custom client or similar (eg. "./files/tibia.rar")
?>

You need only copy/paste all the pages and save them to a working directory of your choice. You can edit database.php and serverinfo.php to your liking.
 
I'll test here, but it is a site without the modern ... or would like a layout?
 
Back
Top