Before someone says theres many register scripts, blah blah blah.
I'll say I know, but this is the first one with checking if email is valid without email activation.
If you dont have 'email' row at your 'users' table, create it.
Register Features:
- Checks if email is valid
- Checks if password is 5-12 characters
- Checks if username is 5-12 characters
- Checks if username is already in use
- Checks if email is already in use
- Checks if 'password' and 'password again' are same
PHP Code:<?php
$con = mysql_connect("127.0.0.1","root","");
mysql_select_db("maplestory", $con);
$username = $_POST['id'];
$password = $_POST['pw'];
$password2 = $_POST['pw2'];
$email = $_POST['email'];
$query = sprintf("SELECT username FROM users WHERE username= '%s'", $username);
$result = mysql_query($query, $con) or die (mysql_error());
$found = mysql_num_rows($result);
$query2 = sprintf("SELECT email FROM users WHERE email= '%s'", $email);
$result2 = mysql_query($query2, $con) or die (mysql_error());
$found2 = mysql_num_rows($result2);
$reg = "^([a-zA-Z0-9]+[_a-zA-Z0-9]+)(\.[-_a-zA-Z0-9]+)*@([-_a-zA-Z0-9]{2,}\.){1,}([a-zA-Z]{2,7})$";
if(strlen($username) < 5)
{
echo "<font color=red>Login ID must be 5 to 12 characters long.</font><br />";
}
else if(strlen($password) < 5)
{
echo "<font color=red>Password must be 5 to 12 characters long.</font><br />";
}
else if(!ereg($reg, $email))
{
echo "<font color=red>Please enter a valid email.</font><br />";
}
else if($found)
{
echo "<font color=red>Login ID <i>$username</i> is already registered.</font><br />";
}
else if($password !== $password2)
{
echo "<font color=red>Passwords didn't match.</font><br />";
}
else if($found2)
{
echo "<font color=red>Email <i>$email</i> is already in use.</font><br />";
}
else
{
$id = 1;
$result = mysql_query("SELECT * FROM Users ORDER BY id ASC");
while($row = mysql_fetch_array($result))
{
if($id==$row['ID'])
{
$id++;
}
}
mysql_query("INSERT INTO users (ID,username,password,email,pin,gender,gm) VALUES ('".$id."', '".$username."', '".$password."', '".$email."', 0, 0, 0)") or die (mysql_error());
echo "<font color=green>Succesfully registered! Press <a href=\"login.php\">here</a> to login.</font><br />";
$username = "";
$password = "";
$password2 = "";
$email = "";
}
mysql_close($con);
?>
<form action="<?php echo $_server['php-self'] ?>" method="post">
<table cellpadding="5" cellspacing="0" border="0">
<tr>
<td id="txt">Login ID:</td>
<td><input value="<?php echo $username; ?>" type="text" name="id" maxlength="12" style="width:150px; border: 1px solid gray;"></td>
</tr>
<tr>
<td id="txt">Password:</td>
<td><input value="<?php echo $password; ?>" type="password" name="pw" maxlength="12" style="width:150px; border: 1px solid gray;"></td>
</tr>
<tr>
<td id="txt">Password again:</td>
<td><input value="<?php echo $password2; ?>" type="password" name="pw2" maxlength="12" style="width:150px; border: 1px solid gray;"></td>
</tr>
<tr>
<td id="txt">Email:</td>
<td><input value="<?php echo $email; ?>" type="text" name="email" maxlength="30" style="width:150px; border: 1px solid gray;"></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="Submit""></td>
</tr>
</table>
</form>
Login Features:
- Checks if password is valid
- Checks if that password belongs to the username entered
- Cookie for 1 hour
Replace 'yourcookie' with something. Ex. your maplestory servers name.
(Theres 2 of them)
And yeah, It's ugly from outside. But it's ment to include at your site so, doesn't matter.PHP Code:<?php
if(isset($_COOKIE['yourcookie']))
{
echo "<br /><br />You've already logged in.";
}
else
{
$con = mysql_connect("127.0.0.1","root","");
mysql_select_db("maplestory", $con);
if (isset($_POST['submit'])) {
$username = $_POST['id'];
$password = $_POST['pw'];
$query = sprintf("SELECT username, password FROM users WHERE username= '%s' AND password= '%s' ", $username, $password);
$result = mysql_query($query, $con) or die (mysql_error());
$found = mysql_num_rows($result);
if($found)
{
$hour = time() + 3600;
setcookie(yourcookie, $username, $hour);
header("Location: index.php");
}
else
{
echo "<br /><br /><font color=red>Incorrect login id or password, please try again.</font><br />";
}
}
mysql_close($con);
?>
<form action="<?php echo $_server['php-self'] ?>" method="post">
<table cellpadding="5" cellspacing="0" border="0">
<tr>
<td id="txt">Login ID:</td>
<td><input value="" type="text" name="id" style="width:150px; border: 1px solid gray;"></td>
<td rowspan="2"><input type="submit" name="submit" value="Login"></td>
</tr>
<tr>
<td id="txt">Password:</td>
<td><input value="" type="password" name="pw" style="width:150px; border: 1px solid gray;"></td>
</tr>
</table>
</form>
+ <a href="register.php">Haven't signed up yet?</a><br />
<?php
}
?>






