Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //no reason for session_start, just connect to the db here
- require_once("db.php");
- //This code runs if the form has been submitted
- if (isset($_POST['submit'])) {
- //mysql_real_escape_string() is used to sanitize the inputs, if you don't people could hack your entire db. :)
- $_POST['password'] = mysql_real_escape_string($_POST['password']);
- $_POST['password2'] = mysql_real_escape_string($_POST['password2']);
- $_POST['username'] = mysql_real_escape_string($_POST['username']);
- // same function like before
- function enchsetenev($toencode,$times)
- {
- $salt = 's+(_a*';
- for($zo=0;$zo<$times;$zo=$zo+1)
- {
- $toencode = hash('sha512',$salt.$toencode);
- $toencode = md5($toencode.$salt);
- }
- return $toencode;
- }
- $password = enchsetenev("{$_POST['password']}",500); // if you change the 500, make sure to change it in the login script also BEFORE PEOPLE REGISTER.
- // change inputs to easier variables
- $username = $_POST['username'];
- //This makes sure they did not leave any fields blank
- if (!$_POST['username'] | !$_POST['password'] | !$_POST['password2']) {
- echo'<body bgcolor="black" text="white">You did not complete all of the required fields</body>';
- }
- // checks if the username is in use
- if (!POST_magic_quotes_gpc()) {
- $username = addslashes($username);
- }
- $usercheck = $_POST['username'];
- $check = mysql_query("SELECT username FROM user WHERE username = '{$usercheck}'")
- or die(mysql_error());
- $check2 = mysql_num_rows($check);
- //if the name exists it gives an error
- if ($check2 != 0) {
- echo '<body bgcolor="black" text="white">Sorry, the username '.$_POST['username'].' is already in use.</body>';
- }
- // this makes sure both passwords entered match
- if ($_POST['password'] != $_POST['password2']) {
- echo '<body bgcolor="black" text="white">Your passwords did not match. </body>';
- }
- // i insert the ip so you can check it if you want.
- // here you would also ban some guys with certain ips.
- $ip=$_SERVER['REMOTE_ADDR'];
- // now we insert it into the database
- $insert = "INSERT INTO user (username, password,ip)
- VALUES ('$username', '$password','{$ip}')";
- $add_member = mysql_query($insert);
- ?>
- <h1>Registered</h1>
- <p>Registering Complete<br />
- <body bgcolor="black" text="white" alink="white" vlink="white" link="white">Thank you, you may now <a href="login.php">Log in</a></body>.</p>
- <?php
- }
- else
- {
- ?>
- <title> Register</title>
- <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
- <table border='1' bordercolor='1166ff' align='center' bgcolor='black'><tr><td>
- <table border="0">
- <tr><th><h2 align='center'>Register</h2></th></tr>
- <tr><td>Username:</td><td>
- <input type="text" name="username" maxlength="16">
- </td></tr>
- <tr><td>Password:</td><td>
- <input type="password" name="password" maxlength="50">
- </td></tr>
- <tr><td>Confirm Password:</td><td>
- <input type="password" name="password2" maxlength="50">
- </td></tr>
- <tr><th colspan=2><input type="submit" name="submit" value="Register"></th></tr> </table></tr></td></table>
- </form><body bgcolor="black" text="white" link="white" alink="white" vlink="white">
- <?php
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment