title: php: session not working while running live on server
body: <p>I am working on a project of PHP. I have a strange error. My PHP project is working well on local server (WAMP server). But after hosting it on live server, it is not working.</p>
  
  <p><strong>Problem:</strong> Session variable created on <code>Login.php</code> page is not passing value on <code>Report.php</code> page. The code is as below:</p>
  
  <p><strong>Login.php</strong></p>
  
  <pre><code>&lt;?php
  $con=mysql_connect("mysql51****************","username","password")or die(mysql_error());
  $select_db=mysql_select_db("database_name",$con);
  $error="";
  
  if(isset($_POST['submit']))
  {
      $userid=mysql_real_escape_string($_POST['username']);
      $password=mysql_real_escape_string($_POST['password']);
      $sql="SELECT * FROM user_details WHERE user_name='{$userid}' AND password='{$password}' ";
  
      $result = mysql_query($sql);
      if(mysql_num_rows($result) &lt;= 0)
      {
          $error="Invalid UserId or Password.";
      }
      else
      {
          //session_set_cookie_params(60*60*60, '/', '.abcxyz.com');
          ini_set('session.cookie_domain','.abcxyz.com');
      session_start();
      //$userid=mysql_real_escape_string($_POST['abc']);
      //echo($userid);
      $_SESSION['user']=$userid;
      $_SESSION['userid']="true";
      //echo $_SESSION['userid'];
      $error="Successfully Login";
      //header("Location: admin.php?page=report");
      /*echo '&lt;script type="text/javascript"&gt;alert("header is not working.' . $_SESSION['user'] . '");&lt;/script&gt;';
  */  ?&gt;
      &lt;script type="text/javascript"&gt;
          /*alert("Please select a Source And Destination Country");  */
          window.location.href='admin.php?page=report';
      &lt;/script&gt;       
  &lt;?php
  
      }
  }
  ?&gt;
  
  &lt;br /&gt;
  
    &lt;h1 style="text-align:center"&gt;Login&lt;/h1&gt;
    &lt;form  class="login"  action="login.php" method="post" name="form1" id="form1"&gt;
    &lt;p&gt;Username:&lt;/p&gt;
        &lt;input class="login-input" type="text" name="username" value=""/&gt;
  
      &lt;p&gt; Password : &lt;/p&gt;
        &lt;input class="login-input" type="password" name="password" value=""/&gt;
  
    &lt;p&gt;
      &lt;p style="color:#F00; font-size:12px; font-weight:100"&gt;&lt;?php echo htmlentities($error); ?&gt;  &lt;/p&gt;
      &lt;input  class="login-submit" type="submit" name="submit" value="Login"/&gt;    
  &lt;/form&gt;
  </code></pre>
  
  <p><strong>Report.php</strong></p>
  
  <pre><code>&lt;?php
  include("connections/Connections.php");
  /*$con=mysql_connect("localhost","admin","")or die(mysql_error());
  $select_db=mysql_select_db("test",$con);*/
  /*session_start();
  if(session_is_registered('test'))
  {
      echo"registered";
  }
  else
  {
      header("Location: login.php");
  }*/
  
  //$user=$_SESSION['userid'];
  
  $user=$_SESSION['userid'];
  echo '&lt;script type="text/javascript"&gt;alert("header is not working.' .$user . '");&lt;/script&gt;';
  if($user=="true")
  {
      //echo " Logining Successfully.";
  }
  else
  {
      ?&gt;
  
      &lt;script type="text/javascript"&gt;
          //alert("Please select a Source And Destination Country");  
          window.location.href='login.php';
      &lt;/script&gt;
  &lt;?php
      //header("Location: login.php");
  }
  ?&gt;
  &lt;?php
  /*session_start();
  $user=$_SESSION['userid'];
  echo($user);
  if($user=="Admin")
  {
      echo " Logining Successfully.";*/
  
  $sql="SELECT * FROM register ";
  if(isset($_POST['btnfilter']))
  {
      $search_term=mysql_real_escape_string($_POST['search_text']);
      $answer = $_POST['filter'];  
      if ($answer == "ID") {          
          $sql .="WHERE id= '{$search_term}' ";
      }
      elseif ($answer == "Name") {          
          $sql .="WHERE fullname Like '%{$search_term}%'";
      }
      elseif ($answer == "DOB") {          
          $sql .="WHERE dob Like '%{$search_term}%' ";
      }
      elseif ($answer == "Occupation") {          
          $sql .="WHERE occupation Like '%{$search_term}%' ";
      }
      else
      {
          echo("Pealse Enter a valid value"); 
      }
  }
  elseif(isset($_POST['btnrmfilter']))
  {
      $sql="SELECT * FROM register";
  }
  
  $query=mysql_query($sql) or die(mysql_errno());
  //}
  /*else
  {
      header('Location: /login.php');
  }*/
  ?&gt;
  
  &lt;style type="text/css"&gt;
      table
      {
          font-size:12px;border-bottom:1px solid #ccc;
      border-left:1px solid #ccc}
      td 
      { 
      padding:5px 3px;
      border-top:1px solid #ccc;
      border-right:1px solid #ccc}
  &lt;/style&gt;
  
    &lt;div class="content"&gt;
    &lt;h1&gt;Data Reading From database.&lt;/h1&gt;
    &lt;form id="search_form" method="post" action=""&gt;
    &lt;div class="radio"&gt;
        &lt;input type="radio" name="filter" value="ID" /&gt;ID
        &lt;input type="radio" name="filter" value="Name" /&gt;Name
        &lt;input type="radio" name="filter" value="DOB"/&gt;DOB
        &lt;input type="radio" name="filter" value="Occupation"/&gt;Occupation&lt;br /&gt;
    &lt;/div&gt;
    &lt;div class="input" &gt;
        &lt;input   type="text" name="search_text" value=""/&gt;
        &lt;input  type="submit" value="FilterData" name="btnfilter" /&gt;     
        &lt;input  type="submit" value="RemoveFilter" name="btnrmfilter" /&gt;
    &lt;/div&gt;
    &lt;/form&gt;
  
      &lt;table border="0" cellpadding="0" cellspacing="0"&gt;
       &lt;colgroup&gt; 
      &lt;col width="2%" style="color:#f60" valign="middle" align="center" &gt;
      &lt;col width="12%" &gt;
      &lt;col width="8%" &gt;
      &lt;col width="5%" align="center" &gt;
      &lt;col width="10%" &gt;
  
      &lt;/colgroup&gt;
        &lt;tr style="background:#eee; height:30px;"&gt;
          &lt;td&gt;ID&lt;/td&gt;
          &lt;td&gt;Name&lt;/td&gt;
          &lt;td&gt;DOB&lt;/td&gt;
          &lt;td&gt;Nationality&lt;/td&gt;
          &lt;td&gt;Mobile No&lt;/td&gt;
          &lt;td&gt;Phone No&lt;/td&gt;
          &lt;td&gt;Email&lt;/td&gt;
          &lt;td&gt;Education&lt;/td&gt;
          &lt;td&gt;Occupation&lt;/td&gt;
          &lt;td&gt;Comment&lt;/td&gt;
          &lt;td &gt;Noofexp&lt;/td&gt;
        &lt;/tr&gt;
  
          &lt;?php while($row = mysql_fetch_array($query)) { ?&gt;
            &lt;tr&gt;
            &lt;td&gt;&lt;?php echo $row['id']; ?&gt;&lt;/td&gt;
            &lt;td&gt;&lt;?php echo $row['fullname']; ?&gt;&lt;/td&gt;
            &lt;td&gt;&lt;?php echo $row['dob']; ?&gt;&lt;/td&gt;
            &lt;td&gt;&lt;?php echo $row['nationality']; ?&gt;&lt;/td&gt;
            &lt;td&gt;&lt;?php echo $row['mobno']; ?&gt;&lt;/td&gt;
            &lt;td&gt;&lt;?php echo $row['phno']; ?&gt;&lt;/td&gt;
            &lt;td&gt;&lt;?php echo $row['email']; ?&gt;&lt;/td&gt;
            &lt;td&gt;&lt;?php echo $row['education']; ?&gt;&lt;/td&gt;
            &lt;td&gt;&lt;?php echo $row['occupation']; ?&gt;&lt;/td&gt;
            &lt;td&gt;&lt;?php echo $row['comment']; ?&gt;&lt;/td&gt;
            &lt;td&gt;&lt;?php echo $row['noofexp']; ?&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;?php } ?&gt;
      &lt;/table&gt;
      &lt;h2&gt;&amp;nbsp;&lt;/h2&gt;
      &lt;h3&gt;Thanks for view.&lt;/h3&gt;
  
      &lt;!-- end .content --&gt;&lt;/div&gt;
    &lt;div class="footer"&gt;
      &lt;p&gt;Footer&lt;/p&gt;
  
  &lt;!-- end .footer --&gt;&lt;/div&gt;
    &lt;!-- end .container --&gt;&lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>Edit:</strong></p>
  
  <p>As the answers suggested, i edited as below:</p>
  
  <p><strong>Login.php:</strong></p>
  
  <pre><code>&lt;?php
  session_start();
  $con=mysql_connect("mysql51*************","username","password")or die(mysql_error());...
  ...
  </code></pre>
  
  <p><strong>Report.php:</strong></p>
  
  <pre><code>&lt;?php
  session_start();
  include("connections/Connections.php");...
  ...
  </code></pre>
  
  <p>But still i am not getting the session variable value in <code>Report.php</code>.</p>