title: Session based login doesn't work on remote server
body: <p>I'm currently building a php based login for a website which happens to work in my localhost created with Wamp, but it does not work if I copy my files over to a remote server and set up the same database there. The connection with the database should be okay, because I can register a new user on the site and the site also shows everything that is to be taken off from the database.</p>
  
  <p>The problem with the login part of the site is that it just simply doesn't do anything at all. I try to login, and if it's with the proper account details, it says login is succesful and it also echoes the session variables for testing purposes (for example: it shows the given user's ID that is saved in the database). But when I navigate to an other page, the user is just not logged in at all. I'll try to list all the code here that should be important to see what's the problem:</p>
  
  <p>The login form:</p>
  
  <pre><code>&lt;form action="submit.php" method="POST" id="loginForm"&gt;
      &lt;fieldset&gt;
          &lt;table id="form_Table"&gt;
              &lt;tr&gt;
                  &lt;td&gt;&lt;label for="login_Username"&gt;Username&lt;/label&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;input type="text" name="login_Username" id="login_Username" class="" /&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;&lt;label for="login_Password"&gt;Password&lt;/label&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;input type="password" name="login_Password" id="login_Password" class="" /&gt;&lt;/td&gt;
              &lt;/tr&gt;
          &lt;/table&gt;
      &lt;p class="submit"&gt;&lt;input type="submit" name="login_Submit" value="Log in" /&gt;&lt;/p&gt;
      &lt;/fieldset&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>The php code which handles the login procedure in the submit.php:</p>
  
  <pre><code>if (isset($_POST['login_Submit'])) { 
      if (!empty($_POST['login_Username']) &amp;&amp; !empty($_POST['login_Password'])) {
  
          $username = mysql_real_escape_string($_POST['login_Username']);
          $password = md5(mysql_real_escape_string($_POST['login_Password']));
  
          $sql = "SELECT * FROM `users` WHERE `username` = '$username' AND `password` = '$password'";
          $checklogin = mysql_query($sql);
  
  
          $result = mysql_query($sql);
          if($result === FALSE) {
              die(mysql_error());
          }
  
          if(mysql_num_rows($checklogin) == "1") {
              $row = mysql_fetch_array($checklogin);
              $group = $row['group'];
              $userid = $row['id'];
              $cart = array();
              $_SESSION['Username'] = $username;
              $_SESSION['Group'] = $group;
              $_SESSION['UserID'] = $userid;
              $_SESSION['LoggedIn'] = 1;
              $_SESSION['cart'] = $cart; 
              echo '&lt;h1&gt;Logged in successfully!&lt;/h1&gt;';
              //echo '&lt;meta http-equiv="refresh" content="1;index.php"&gt;';
              echo $_SESSION['Username'];
              echo $_SESSION['LoggedIn'];
              echo $_SESSION['UserID'];
              echo $_SESSION['Group'];
              } else {
              echo '&lt;h1&gt;Wrong username or password!&lt;/h1&gt;';
                  }
              }
          }
  </code></pre>
  
  <p>index.php:</p>
  
  <pre><code>&lt;?php
  @session_start();
  include 'header.php';
  ?&gt;
  </code></pre>
  
  <p>connection.php:</p>
  
  <pre><code>&lt;?php
  @session_start();
  
  //connect variables are here
  
  mysql_connect($dbhost, $dbuser, $dbpass) or die("MySQL connection error: " . mysql_error());  
  mysql_select_db($dbname) or die("MySQL database error: " . mysql_error());
  mysql_query('SET NAMES utf8');
  
  ?&gt; 
  </code></pre>
  
  <p>header.php:</p>
  
  <pre><code>&lt;?php include 'connection.php'; 
  @session_start();?&gt;
  </code></pre>
  
  <p>My best guess was that for some reason the site does not keep the session variables after I leave the given page, that's why I added the @session_start() to multiple pages, but it does not work this way either.</p>
  
  <p>As I have ran out of ideas of what could I do now, any help would be greatly appreciated. Thank you.</p>