title: setting cookie and unable to read them in different php file
body: <p>I have a small application and now it is time to include a login game on top of everything. Just got it up and running on the real world ( :P )</p>
  
  <p>Here is my code on login page (login.php):</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;
          Login
      &lt;/title&gt;
      &lt;meta charset="UTF-8"&gt;
      &lt;script src="https://www.google.com/recaptcha/api.js" async defer&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;?php include_once("analyticstracking.php") ?&gt;
      &lt;form action="login.php" method="POST"&gt;
  
  
  
      &lt;?php
              if (isset($_POST['user']) &amp;&amp; isset($_POST['password']))
              {
                  if(isset($_POST['g-recaptcha-response']) &amp;&amp; !empty($_POST['g-recaptcha-response']))
                  {
                      $secret = '';
                      $verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secret.'&amp;response='.$_POST['g-recaptcha-response']);
                      $responseData = json_decode($verifyResponse);
  
                      if($responseData-&gt;success)
                      {                   
                          $user = $_POST['user'];
                          $password = $_POST['password'];
  
                          $salt = "d5f332312e3e390c81f6ef9f242c21bf9e472d6296ddd4bebddd0f54eb576f14";
  
  
                          $hpassword = hash('sha256', $salt . $password);
  
                          $_COOKIE['user'] = $user;
                          $_COOKIE['pass'] = $hpassword;
  
                          $auth = 1;
                          $_COOKIE['authorized'] = $auth;
  
  
  
                          setrawcookie("user", $user, time() + 28800, "/",'domaindig.eu');
                          setrawcookie("hpass", $hpassword, time() + 28800, "/",'domaindig.eu');
                          setrawcookie("authorized", $auth, time() + 28800, "/",'domaindig.eu');
  
                          print_r($_COOKIE);
  
                          header( 'Location: check.php');
                      }
                  }
              }
      ?&gt;
  
      username: &lt;input name="user" type="user"&gt;&lt;br&gt;
      password: &lt;input name="password" type="password"&gt;&lt;br&gt;
      &lt;div class="g-recaptcha" data-sitekey=""&gt;&lt;/div&gt;
      &lt;input type="submit" value="Submit" /&gt;&lt;br&gt;&lt;br&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>As you may see, I used google recaptcha i order to prevent brute force logins. As of that time (when i inserted repcatcha), none of my $_SESSION variables worked ever again. So, I decided to work with cookies (new experiance, due to always use of sessions).</p>
  
  <p>So far, so good.</p>
  
  <p>When I finished coding this php page, I moved on finishing php file, check.php. In this file I check the credentials and if everything checks out, I redirect to main page and menu (without any graphs yes, only pure php).</p>
  
  <p>My problem is:</p>
  
  <p>On the second file, I can't see any cookie. I use print_r($_COOKIE); and I see only cookies from recaptcha. On login page, I see the 3 cookies that I am trying to set, but on the other files, it seems I cannot read them. I checked multiple browsers and multiple computers, but with the same luck. I have verify, that the browsers can accept cookies, but it seems I have made a mistake.</p>
  
  <p>If something is foggy about my description, please let me know, and I will clarify.</p>
  
  <p>Here is my check.php code (which checks the credentials using cookies):</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;
          check
      &lt;/title&gt;
      &lt;meta charset="UTF-8"&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;?php include_once("analyticstracking.php") ?&gt;
      &lt;form action="check.php" method="POST"&gt;
  
          &lt;?php
          if ($_COOKIE['authorized'] == 1)
          {
              if (isset($_COOKIE['user']) || isset($_COOKIE['hpass']))
              {
                  require('ConnectToDB.php');
  
                  $username = $_COOKIE['user'];
                  $password = $_COOKIE['hpass'];
  
                  $result="SELECT `password` FROM `users` WHERE username = '$username'";
                  $tbl=mysqli_query ($conn, $result);
  
                  $table = $tbl-&gt;fetch_assoc();
                  $pass = $table['password'];
  
                  if ($pass)
                  {
                      if ($password == $pass)
                      {
                          $ip = $_SERVER['REMOTE_ADDR'];  
                          $date = date("Y-m-d H:i:s");
  
                          $result = "INSERT INTO `logins` ( `username`, `date`, `ip`) VALUES ('$username', '$date', '$ip')";
                          $tbl = mysqli_query($conn, $result);
                          $_COOKIE['authorized'] = 1;
                          echo "Login successfull! Redirecting.";
  
  
                          require 'ConnectToDB.php';
  
                          $alphanumeric[0] = "0";
                          $alphanumeric[1] = "1";
                          $alphanumeric[2] = "2";
                          $alphanumeric[3] = "3";
                          $alphanumeric[4] = "4";
                          $alphanumeric[5] = "5";
                          $alphanumeric[6] = "6";
                          $alphanumeric[7] = "7";
                          $alphanumeric[8] = "8";
                          $alphanumeric[9] = "9";
                          $alphanumeric[10] = "a";
                          $alphanumeric[11] = "b";
                          $alphanumeric[12] = "c";
                          $alphanumeric[13] = "d";
                          $alphanumeric[14] = "e";
                          $alphanumeric[15] = "f";
                          $alphanumeric[16] = "g";
                          $alphanumeric[16] = "h";
                          $alphanumeric[17] = "i";
                          $alphanumeric[18] = "j";
                          $alphanumeric[19] = "k";
                          $alphanumeric[20] = "l";
                          $alphanumeric[21] = "m";
                          $alphanumeric[22] = "n";
                          $alphanumeric[23] = "o";
                          $alphanumeric[24] = "p";
                          $alphanumeric[25] = "q";
                          $alphanumeric[26] = "r";
                          $alphanumeric[27] = "s";
                          $alphanumeric[28] = "t";
                          $alphanumeric[29] = "u";
                          $alphanumeric[30] = "v";
                          $alphanumeric[31] = "w";
                          $alphanumeric[32] = "x";
                          $alphanumeric[33] = "y";
                          $alphanumeric[34] = "z";
                          $alphanumeric[35] = "A";
                          $alphanumeric[36] = "B";
                          $alphanumeric[37] = "C";
                          $alphanumeric[38] = "D";
                          $alphanumeric[39] = "E";
                          $alphanumeric[40] = "F";
                          $alphanumeric[41] = "G";
                          $alphanumeric[42] = "H";
                          $alphanumeric[43] = "I";
                          $alphanumeric[44] = "J";
                          $alphanumeric[45] = "K";
                          $alphanumeric[46] = "L";
                          $alphanumeric[47] = "M";
                          $alphanumeric[48] = "N";
                          $alphanumeric[49] = "O";
                          $alphanumeric[50] = "P";
                          $alphanumeric[51] = "Q";
                          $alphanumeric[52] = "R";
                          $alphanumeric[53] = "S";
                          $alphanumeric[54] = "T";
                          $alphanumeric[55] = "U";
                          $alphanumeric[56] = "V";
                          $alphanumeric[57] = "W";
                          $alphanumeric[58] = "X";
                          $alphanumeric[59] = "Y";
                          $alphanumeric[60] = "Z";
  
                          global $session;
                          $session = "";
  
                          for ($i=0;$i&lt;20;$i++)
                          {
                              $rnd = rand(0, 60);
                              $session .= $alphanumeric[$rnd];
                          }
  
  
                          $date = date("Y-m-d");
                          $ip = $_SERVER['REMOTE_ADDR']; 
  
                          $result = "INSERT INTO `sessions` ( `user`, `date`, `session_id`, `ip`, `login`) VALUES ('$username', '$date', '$session', '$ip', '1')";
                          $tbl = mysqli_query($conn, $result);                            
  
                          echo "All done";
                          echo '&lt;script&gt; window.location = "https://domaindig.eu/index.php" &lt;/script&gt;';
                      }
                      else
                      {
                          echo "User found but password provided was wrong. Try again!";
                      //  echo '&lt;script&gt; window.location = "https://domaindig.eu/login.php" &lt;/script&gt;';
                      }
                  }
                  else
                  {
                      echo "Failure. Couldn't fetch password!!! Try again.";
                      //echo '&lt;script&gt; window.location = "https://domaindig.eu/login.php" &lt;/script&gt;';
                  }
              }
              else
              {
                  echo "Something went wrong. Try login again!";
                  //echo '&lt;script&gt; window.location = "https://domaindig.eu/login.php" &lt;/script&gt;';
              }
          }
          else
          {
              echo "Unauthorized access!!";
              //echo '&lt;script&gt; window.location = "https://domaindig.eu/login.php" &lt;/script&gt;';
          }
  
          ?&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Here are also a picture of my cookies when I show them on login page:</p>
  
  <p><a href="https://i.stack.imgur.com/phgwV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/phgwV.png" alt="enter image description here"></a></p>
  
  <p>I thank everyone in advance.</p>