0

Everything works fine on localhost but when I put it on live server my header is not redirecting after log in and thus session is not being set so my user information is not showing up in the top right corner until I manually refresh the page or navigate to other page. Note that it is not redirecting to any page I put.

header.php:

session_start();
$userid=$_SESSION['userid'];
$username=$_SESSION['username'];

index.php:

include "header.php";
if($username && $userid)
   {
      echo "You are logged in as <b>$username</b>";
   }
 else
   {
    $form="<form action='index.php' method='post'>
           <table>
              <tr>
              <td>Username:</td>
              <td><input type='text' name='user'></td>
              </tr>

              <tr>
              <td>Password:</td>
              <td><input type='password' name='pass'></td>
              </tr>

              <tr>
              <td><input type='submit' name='submit' value='login'></td>
              </tr>

              <tr>
              <td><a href='register.php'>Register</a></td>
              <td><a href='forgotpass.php'>Forgot password?</td>
              </tr>
           </table>
           </form>";

  if(isset($_POST['submit']))
   {
    $user=htmlentities($_POST['user']);
    $pass=htmlentities($_POST['pass']);

    if($user)
      {
         if($pass)
          {
           require 'connect.php';
           $pass=md5(md5("123".$pass."456"));
           $query=mysqli_query($conn,"SELECT*FROM user WHERE username='$user'");
           $numrows=mysqli_num_rows($query);

           if($numrows==1)
              {
                $row=mysqli_fetch_assoc($query);
                $dbusername=$row['username'];
                $dbid=$row['id'];
                $dbpass=$row['password'];
                $dbactive=$row['active'];

                if($pass==$dbpass)
                  {
                    if($dbactive==1)
                      {
                       $_SESSION['username']=$dbusername;
                       $_SESSION['userid']=$dbid;
                       header("Location:index.php");
                      }
                     else
                      {
                        echo "You must activate your account.$form";
                      }
                  }
                else 
                  {
                    echo "Incorrect password.$form";
                  }
              }
            else
              {
                echo "Incorrect username.$form";
              }

            mysqli_close($conn);
          }
        else
          {
           echo "You must enter password.$form";
          }
       }
     else
       {
        echo "You must enter username.$form";
      }
   }
else
  {
    echo $form;
  }
}
vivekpansara
  • 895
  • 1
  • 6
  • 14
admir
  • 193
  • 16
  • Enable proper error reporting in your `php.ini` file so you can at least see any warning messages, eg `error_reporting = E_ALL` and `display_errors = On` – Phil Mar 21 '14 at 03:59
  • You cannot echo anything out before a header, so move your PHP code so that it's at the top of the page and not after your form. – Ohgodwhy Mar 21 '14 at 04:00
  • thanks for replies i cannot move my code to the top page because i am echoing $form in else stattement and form needs to be in a form div so i used some javascript instead of header.I used echo ""; and now it works fine – admir Mar 21 '14 at 04:23

0 Answers0