title: php session is lost when using my IP instead of localhost
body: <p>im using xampp, my session is always lost when im using my IP instead of localhost/
  how can i keep the session? it works ok if i use localhost/ </p>
  
  <pre><code>&lt;?php 
  require '/mysqli.php';
  
  header("Access-Control-Allow-Origin: *");
  header("Access-Control-Allow-Methods: POST");
  header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
  header("Access-Control-Allow-Credentials: true");
  </code></pre>
  
  <p>header('Access-Control-Max-Age: 1000');
      header('Content-Type: application/json');</p>
  
  <pre><code>$myJson = json_decode(file_get_contents('php://input'));
  
  $action = $myJson-&gt;action;
  
  session_start();
  if($action == 'login') {
      $myJson-&gt;password ? $role='admin' : $role='encoder';
  
      $_SESSION['username'] = $myJson-&gt;username;
      $_SESSION['role'] = $role;
      $_SESSION['id'] = session_id();
  
      if($role =='admin'){
          $sql = "SELECT * FROM `users` WHERE `username`='".$myJson-&gt;username."' AND `password`='".md5($myJson-&gt;password)."'";
  
          // $_SESSION['status'] = 
          $result = mysqli_query($conn, $sql);
          if(mysqli_num_rows($result) == 1){
              $_SESSION['status'] = "Login success.";
          } else {
              session_unset();
              session_destroy();
              $_SESSION['status'] = "Login failed.";
          }
      } else {
          $_SESSION['status'] = "Login success.";
      }
  
  } else if ($action == 'logout') {
      session_unset();
      session_destroy();
      $_SESSION['status'] = "Logged out.";
  } else if ($action == 'check' &amp;&amp; session_id() == ''){
      $_SESSION['username'] = $_SESSION[''];
      $_SESSION['role'] = $_SESSION[''];
      $_SESSION['id'] = $_SESSION[''];
      var_dump($_SESSION);
  }
  
  echo json_encode($_SESSION);
  </code></pre>
  
  <p>?></p>