Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //INDEX
- <html>
- <form action='login.php' method='POST'>
- Username: <input type='text' name='username'><br>
- Password: <input type='password' name='password'><br>
- <input type='submit' value='Log in'>
- </form> <p>
- <a href='register.php'>Register?</a>
- </html>
- //LOGIN
- <?php
- session_start();
- $username = $_POST['username'];
- $username = $_POST['password'];
- if ($username&&$password)
- {
- $connect = mysql_conncet("localhost","root","") or die ("Couldn't connect!");
- mysql_select_db ("login") or die ("couldn't find db");
- $query = mysql_query("SELECT * FROM users WHERE username='$username'");
- $numrows = mysql_num_rows($query);
- if ($numrows!=0)
- {
- while ($row =mysql_fetch_assoc($query))
- {
- $dbusername = $row ['username'];
- $dbpassword = $row ['password'];
- }
- //check to see if they match!
- if ($username==$dbusername&&$password==$dbpassword)
- {
- echo "You're in!<a href='member.php'>Click</a> here to enter the memberpage";
- $_SESSION['username']=$username;
- }
- else
- echo "Incorrect password!";
- }
- else
- die ("That user doesen't exsist!");
- }
- else
- die("Please enter username and a password!");
- ?>
- //LOGOUT
- <?php
- sessoin_start();
- session_destroy();
- echo "You've been loggged out. <a href='index.php'>Click</a> here to return";
- ?>
- //MEMBER
- <?php
- session_start();
- if ($_SESSION['username'])
- echo "Welcome, ".$_SESSION['username']."!<br><a href='logout.php'>Logout</a>";
- else
- die("You must be logged in!");
- ?>
- //REGISTER
- <?php
- echo "<h1>Register</h1>";
- $submit = $_POST['sumbit'];
- $fullname = strip_tags ($_POST['fullname']);
- $username = strip_tags ($_POST['username']);
- $password = strip_tags($_POST['password']);
- $repeatpassword =strip_tags ($_POST['repeatpassword']);
- $date = date ("y-m-d");
- if ($submit)
- //check for existance
- if ($fullname&&$username&&$password&&$repeatpassword)
- {
- if ($password==$repeatpassword)
- {
- //check char length of username and fullname
- if (strlen($username)>25||strlen($fullname)>25)
- {
- echo "Length of username or fullname is too long!";
- }
- else
- {
- //check password length
- if (strlen($password)>25 || strlen($password)<6)
- {
- echo "Password must be between 6 and 25 characteres";
- }
- else
- {
- //register the user!
- //encrypt password
- $passsword = md5($password);
- $repeatpassword = md5 ($repeatpassword);
- //open datatbase
- $connect =mysql_connect ("localhost","root","");
- mysql_selelct_db("login"); //select database
- $queryreg = mysql_query("
- INSERT INTO users VALUES ('','$fullname','$username','$password','$date')
- ");
- echo ("You have been registered!<a href='index.php';>Return to login page</a>");
- }
- }
- echo "Please fill in <b>all</b> fields!";
- }
- }
- ?>
- <html>
- <form action='register.php' method='POST'>
- <table>
- <tr>
- <td>
- Full Name:
- </td>
- <td>
- <input type='text' name='fullname' value='<?php echo $fullname; ?>'>
- </td>
- </tr>
- <tr>
- <td>
- Choose a username:
- </td>
- <td>
- <input type='text' name='username'value='<?php echo $username; ?>'>
- </td>
- </tr>
- <tr>
- <td>
- Choose a password:
- </td>
- <td>
- <input type='password' name='password'>
- </td>
- </tr>
- <tr>
- <td>
- Repeat your password:
- </td>
- <td>
- <input type='password' name='repeatpassword'>
- </td>
- </tr>
- </table>
- <p>
- <input type='submit' name='submit' value='Register'>
- </form>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement