Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Functions.php
- <?php
- FUNCTION protect($string){
- $string = mysql_real_escape_string($string);
- $string = strip_tags($string);
- $string = addslashes($string);
- RETURN $string;
- }
- FUNCTION CONNECT(){
- $con = mysql_connect("localhost", "root", "******") OR die(mysql_error());
- $db = mysql_select_db("members", $con);
- }
- ?>
- <?php
- include_once "functions.php";
- CONNECT();
- IF(!$_POST['submit']){
- echo "<table border=\"0\" cellspacing=\"3\" cellpadding=\"3\">\n";
- echo "<form method=\"post\" action=\"register.php\">\n";
- echo "<tr><td colspan=\"2\" align=\"center\"> Registration</td></tr>\n";
- echo "<tr><td>Username:</td><td><input type=\"text\" name=\"username\"></td></tr>\n";
- echo "<tr><td>Password:</td><td><input type=\"password\" name=\"password\"></td></tr>\n";
- echo "<tr><td>Confirm:</td><td><input type=\"password\" name=\"passconf\"></td></tr>\n";
- echo "<tr><td>Email:</td><td><input type=\"text\" name=\"email\"></td></tr>\n";
- echo "<tr><td colspan=\"2\" align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Register\"></td></tr>\n";
- echo "</form></table>\n";
- echo "<br><br>
- <br>
- <br>
- <br>
- <div align='bottom'>© 2009-2010 <strong>Kazimiya</strong>. <a href='index'>Home</a> | <a href='irc'>IRC</a></div>";
- }ELSE {
- $username = protect($_POST['username']);
- $password = protect($_POST['password']);
- $confirm = protect($_POST['passconf']);
- $email = protect($_POST['email']);
- $errors = array();
- IF(!$username){
- $errors[] = "Username is not defined!";
- }
- IF(!$password){
- $errors[] = "Password is not defined!";
- }
- IF($password){
- IF(!$confirm){
- $errors[] = "Confirmation password is not defined!";
- }
- }
- IF(!$email){
- $errors[] = "E-mail is not defined!";
- }
- IF($username){
- IF(!ctype_alnum($username)){
- $errors[] = "Username can only contain numbers and letters!";
- }
- $range = range(1,32);
- IF(!in_array(strlen($username),$range)){
- $errors[] = "Username must be between 1 and 32 characters!";
- }
- }
- IF($password && $confirm){
- IF($password != $confirm){
- $errors[] = "Passwords do not match!";
- }
- }
- IF($email){
- $checkemail = "/^[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\\.[a-z]{2,}$/i";
- IF(!preg_match($checkemail, $email)){
- $errors[] = "E-mail is not valid, must be name@server.tld!";
- }
- }
- IF($username){
- $sql = "SELECT * FROM `users` WHERE `username`='".$username."'";
- $res = mysql_query($sql) OR die(mysql_error());
- IF(mysql_num_rows($res) > 0){
- $errors[] = "The username you supplied is already in use!";
- }
- }
- IF($email){
- $sql2 = "SELECT * FROM `users` WHERE `email`='".$email."'";
- $res2 = mysql_query($sql2) OR die(mysql_error());
- IF(mysql_num_rows($res2) > 0){
- $errors[] = "The e-mail address you supplied is already in use of another user!";
- }
- }
- IF(COUNT($errors) > 0){
- foreach($errors AS $error){
- echo $error . "<br>\n";
- }
- }ELSE {
- $sql4 = "INSERT INTO `users`
- (`username`,`password`,`email`,`admin`,`time`)
- VALUES ('".$username."','".md5($password)."','".$email."','0','".TIME()."')";
- $res4 = mysql_query($sql4) OR die(mysql_error());
- echo "<br>
- You have successfully registered with the username <b>".$username."</b> and the password of <b>".$password."</b>!";
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement