Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Yahoo Answers' Question: http://answers.yahoo.com/question/index?qid=20130617184009AAPPF2Y
- include('includes/functions.php');
- session_start();
- /*** Message Declaration ***/
- $message = '';
- /*** Functions ***/
- function pv($name){
- $var = (isset( $_POST[$name] ))? trim( $_POST[$name] ) : '';
- return (@mysql_ping())? mysql_real_escape_string( $var ) : addslashes( $var );
- }
- if( isset( $_POST['login'] ) ){
- // Database Connection Needs to go Here.
- // Should at the least be MySQLi Functions
- // MySQL Functions are deprecated
- $username = pv('username');
- $password = pv('password');
- if( isset($username{0}) && isset($password{0})){
- // MD5 Hash Password.
- $password = md5($password);
- $stmt = "SELECT username FROM users WHERE username='{$username}' AND password='{$password}' LIMIT 1";
- $result = mysql_query($stmt);
- if( !$result ){
- $message .= 'Query Statement Error: ' . mysql_error() . '<br />' . PHP_EOL;
- }else if( mysql_num_rows($result) === 1){
- // Username and password are correct.
- $_SESSION['user'] = mysql_fetch_object($result)->username;
- header('Location: index.php');
- exit;
- }else{
- $message .= 'Username / Password Combo is incorrect. Please try again.<br />' . PHP_EOL;
- }
- }else{
- $message .= 'Username and Password are both required fields.<br />' . PHP_EOL;
- }
- }
- /*** Message Formatting ***/
- if( isset($message{1}) ){
- $message = '<div style="width: 500px;margin: auto;position: relative;border: 1px solid #999;">
- <h3 style="margin: 0;padding: 4px;background-color: #999;color: #fff;">Message</h3>
- <p style="padding: 8px;">' . $message . '</p>
- </div>';
- }
- include('login.php');
- ?>
- also For HTML;
- <?php
- session_start(); // Has to be called before any output.
- if( isset($_SESSION['user']) ){
- header('Location: index.php');
- exit;
- }
- ?>
- <html>
- <head>
- <title>Admin Area Login page</title>
- </head>
- <body>
- <?php if(isset($message)){ echo $message; } ?>
- <form action="dologin.php" method="POST">
- <table>
- <tr>
- <td><span>Username:</span></td>
- <td><input type="text" name="username" /></td>
- </tr>
- <tr>
- <td><span>Password:</span></td>
- <td><input type="password" name="password" /></td>
- </tr>
- <tr>
- <td colspan="2" align="right"><input type="submit" name="login" value="Login" /></td>
- </tr>
- </table>
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement