Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Needs to be started before anything has been sent to the user, including whitespace.
- session_start();
- if(isset($_POST['Submit'])){
- include 'connection/conn.php';
- $database="issuelog";
- $selectdb = mysql_selectdb($database);
- if ($selectdb){
- echo "Selected";
- $UserName = $_POST['username'];
- // Password's should never be stored as plain text.
- $Password = $_POST['password'];
- $table = "userreg";
- $sql = "SELECT UserName FROM $table WHERE UserName='{$UserName}' AND Password='{$Password}' LIMIT 1";
- // Including the Connection Resource Link in the query call is the best way. Good Job.
- $results=mysql_query($sql, $conn);
- // Check for successful query
- if( $results && mysql_num_rows($results) === 1){
- // If successful login details, redirect user to 'login_success.php'
- // session_register() is no longer a valid function. It is deprecated in PHP 5.3 and removed from 5.4
- $_SESSION['username'] = $UserName;
- $_SESSION['password'] = $Password;
- if( !headers_sent()){ // Check to see if the headers have already been sent. You cannot send more if they have already been sent.
- header("Location: login_success.php");
- exit;
- }else{
- // If the headers have been sent, send alternative redirect methods.
- echo '<meta http-equiv="refresh" content="0; url=login_success.php"/>');
- echo '<script>document.location.href="login_success.php";</script>';
- exit;
- }
- } else if( !$results ){
- // Query Failed, either because of a server/mysql error
- // or a malformed query statement.
- // echo 'Query [' . $sql . '] Failed because: ' . mysql_error($conn); // Uncomment this line for debugging purposes only
- echo 'Internal Server Error';
- } else {
- echo "Wrong Username or Password.";
- }
- }
- }
- ?>
- login_success.php
- <?php
- session_start();
- if(!isset($_SESSION['username'])){
- header("Location: login.php");
- }
- ?>
- <html>
- <body>
- Login Successful
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement