Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- if(isset($_SESSION['username']) && isset($_SESSION['password'])){
- if($_REQUEST['username'] == "admin" && $_REQUEST['password'] == "secret") {
- header("Location: adminview.php");
- } else {
- header("Location: view.php");
- }
- }
- ?>
- <html>
- <head>
- <meta http-equiv="Content-Language" content="zh-tw" />
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>Nice Form</title>
- <link rel="stylesheet" href="css/formStyle.css" type="text/css" />
- </head>
- <body>
- <br />
- <?php
- if(isset($_SESSION['loginIncorrect'])){
- ?>
- <p align="center"><b>Incorrect username/password combination! Please try again.</b></p>
- <?php
- unset($_SESSION['loginIncorrect']);
- }
- ?>
- <form method="POST" action="login.php">
- <div align="center">
- <table border="0" width="300" class="border">
- <tbody>
- <tr>
- <td colspan="2" class="heading" height="26" align="center">Login
- Information</td>
- </tr>
- <tr>
- <td width="82" class="content">Username:</td>
- <td width="202">
- <input type="text" name="username" size="20" class="content" /></td>
- </tr>
- <tr>
- <td width="82" class="content">Password:</td>
- <td width="202">
- <input type="password" name="password" size="20" class="content" /></td>
- </tr>
- <tr>
- <td width="82"> </td>
- <td width="202">
- <input type="submit" value="Submit" name="submit" class="content" /><input type="reset" value="Reset" class="content" /></td>
- </tr>
- </tbody>
- </table>
- </div>
- </form>
- <a href="register.php">Register</a>
- </body>
- </html>
- //login.php starts here
- <?php
- session_start();
- if($_REQUEST['username'] == "admin" && $_REQUEST['password'] == "secret") {
- $_SESSION['username'] = 'admin';
- $_SESSION['password'] = 'secret';
- header("Location: adminview.php");
- }
- include('connectMySQL.php');
- $db = new MySQLDatabase();
- $db->connect("test", "test", "messageboard");
- $query = "select username,password from users";
- $result = mysql_query($query);
- if($result) {
- while($row = mysql_fetch_array($result)){
- if($_REQUEST['username'] == $row['username'] && $_REQUEST['password']==$row['password']) {
- $_SESSION['username'] = $row['username'];
- $_SESSION['password'] = $row['password'];
- header("Location: view.php");
- }
- }
- }
- else {
- die(mysql_error());
- }
- $_SESSION['loginIncorrect'] = true;
- header("Location: form.php");
- $db->disconnect();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement