Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Connect to server and select databse.
- mysql_connect("$host", "$username", "$password")or die("cannot connect");
- mysql_select_db("$db_name")or die("cannot select DB");
- // username and password sent from form
- $username=$_POST['username'];
- $password=$_POST['password'];
- // To protect MySQL injection
- $username = stripslashes($username);
- $password = stripslashes($password);
- $username = mysql_real_escape_string($username);
- $password = mysql_real_escape_string($password);
- $sql="SELECT * FROM $tbl_name WHERE username='$username' and password='$password'";
- $result=mysql_query($sql);
- // Mysql_num_row is counting table row
- $count=mysql_num_rows($result);
- // If result matched $myusername and $mypassword, table row must be 1 row
- if($count==1){
- // Register $myusername, $mypassword and redirect to file "login_success.php"
- session_register("username");
- session_register("password");
- header("location:login.007?action=success");
- }
- else {
- echo "
- <html>
- <head>
- <link rel=\"stylesheet\" href=\"style.css\" type=\"text/css\">
- <title>Login Failure</title>
- </head>
- <body>
- <div id=\"container\">
- <div class=\"content\">
- <h1 class=\"title\">Login Failed</h1>
- <p class=\"txt\">Incorrect Username/Password combination. If I were you I'd <a href=\"login.007?action=login\">go back</a> and try again.</p>
- </div>
- </div>
- </body>
- </html>
- ";
- }
- }
- if ($action == "success") {
- session_start();
- if(!session_is_registered(myusername)){
- header("location:main_login.php");
- }
- echo "
- <html>
- <head>
- <link rel=\"stylesheet\" href=\"style.css\" type=\"text/css\">
- <title>Login Success</title>
- <meta http-equiv=\"refresh\" content=\"2;url=index.007\">
- </head>
- <body>
- <div id=\"container\">
- <div class=\"content\">
- <h1 class=\"title\">Login Success</h1>
- <p class=\"txt\">You have been logged in and will be redirected to the main page.</p>
- </div>
- </div>
- </body>
- </html>
- ";
- }
- if ($action == "logout") {
- session_start();
- session_destroy();
- echo "
- <html>
- <head>
- <link rel=\"stylesheet\" href=\"style.css\" type=\"text/css\">
- <title>Logout Success</title>
- <meta http-equiv=\"refresh\" content=\"2;url=index.007\">
- </head>
- <body>
- <div id=\"container\">
- <div class=\"content\">
- <h1 class=\"title\">Logout Success</h1>
- <p class=\"txt\">You have been logged out successfully and will be redirected to the main page now.</p>
- </div>
- </div>
- </body>
- </html>
- ";
- }
- if ($action == "login") {
- echo "
- <html>
- <head>
- <link rel=\"stylesheet\" href=\"style.css\" type=\"text/css\">
- <title>Login</title>
- </head>
- <body>
- <div id=\"container\">
- <div class=\"content\">
- <h1 class=\"title\">Login</h1>
- <p class=\"txt\">Please enter your information below.</p>
- <form name=\"loginform\" method=\"post\" action=\"login.007?action=logincheck\">
- <input name=\"username\" type=\"text\" id=\"username\" value=\"Username\" onfocus=\"this.value = '';\"><br>
- <input type=\"text\" id=\"fakepassword\" value=\"Password\" onfocus=\"this.style.display = 'none'; document.getElementById('password').style.display = 'inline'; document.getElementById('password').focus();\">
- <input type=\"password\" id=\"password\" name=\"password\" style=\"display: none;\"><br>
- <input type=\"submit\" value=\"Login\">
- </form>
- </div>
- </div>
- </body>
- </html>
- ";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement