0

for some reason my login isn't redirecting to the required output page ive been stuck in this part for almost an hour i still cant find out whats wrong in this please help and thank you in advance !!

hoody.php

<?php 
session_start();
$error='';
if(isset($_POST['submit']))
    {
        if(empty($_POST['Uname'])||empty($_POST['psd'])){
            $error="enter the user name and password";
        } else {
            $Servername = $_POST['Uname'];
            $serverpass = $_POST['psd'];
            $conn = mysql_connect('localhost','root','') or die("could not connect to server".mysql_error());
            mysql_select_db("khader",$conn) or die ("could not connect to database".mysql_error());
            $query = "select * from person where uname = '$Servername' and pswd = '$serverpass' ";
            $loggy = mysql_query($query,$conn) or die("could not get result".mysql_error());
            $rows = mysql_num_rows($loggy);
            if($rows==1)
                {
                    $_SESSION['login_user']=$Servername;
                    header('profile.php');
                }
            else
                {
                    $error= "username and password is invalid" ;
                }
            mysql_close($conn) or die ("disconnect failed.".mysql_error());
        }
    }


?>

bye.php

<?php
include('hoody.php');
if(isset($_SESSION['login_user'])){
    header('profile.php');
}
?>

<center>
<form method="post">
  <table>
    </table>
  <p class="style1">Login</p>
  <table cellspacing="5">
  <tr></tr>
    <tr>
      <td> Username</td>
      <td><input type="text" name="Uname" /></td>
    </tr>
    <tr>
      <td> Password</td>
      <td><input type="password" name="psd" /></td>
    </tr>
     <tr></tr>
  </table>
  <input name="submit" type="submit" value="Login" />

  <span><?php echo $error; ?></span>
</form>

profile.php

<!DOCTYPE html>
<html>
<head>
<title>Your Home Page</title>
</head>
<body>
<div id="profile">
<b id="welcome">Welcome : <i><?php echo $login_session; ?></i></b>
<b id="logout"><a href="logout.php">Log Out</a></b>
</div>
</body>
</html>
Barmar
  • 741,623
  • 53
  • 500
  • 612
Khader
  • 305
  • 1
  • 4
  • 10
  • Do you have error reporting turned on for your php code? Is there any error that you are getting ? – Maximus2012 May 06 '15 at 16:59
  • [Your script is at risk for SQL Injection.](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) Please, [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). Learn about [prepared statements](http://en.wikipedia.org/wiki/Prepared_statement) instead, and consider using [PDO](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard May 06 '15 at 16:59
  • Also, try adding `session_start();` at the top of bye.php maybe ? – Maximus2012 May 06 '15 at 16:59
  • And profile.php @Maximus2012 – Jay Blanchard May 06 '15 at 17:00
  • @JayBlanchard is it needed on profile.php unless `$login_session;` is coming from session ? – Maximus2012 May 06 '15 at 17:01
  • @Maximus2012 It starts with `include hoody.php`, which has `session_start()`. – Barmar May 06 '15 at 17:01
  • @Barmar you are correct. Thanks. My guess is that most of the errors would have been caught if the OP had error reporting turned on though. – Maximus2012 May 06 '15 at 17:02
  • it shows that the session has already started – Khader May 06 '15 at 17:07

1 Answers1

3

You left out the header name when you called header(). It should be:

header('Location: profile.php');
Barmar
  • 741,623
  • 53
  • 500
  • 612