title: Is it possible to send a php session variable directy with ajax?
body: <p>I've got this in index.php</p>
  
  <pre><code>    &lt;?php
  
      include_once '..\connect.php';
  
      session_start();
  
      if (isset($_SESSION['username'])){
          $player_name = $_SESSION['username'];
  
      } else {    
          header( 'Location: http://localhost/Inventory/index.php' ) ;
          exit;
      }
  
      ?&gt;
  </code></pre>
  
  <p>and im making a ajax request to request.php</p>
  
  <pre><code>    &lt;?php
      //connect to databate and check for errors
      $con = mysql_connect ("localhost","root","");
      if (!$con) {
          die ('Could not connect to database: ' . mysql_error());
      }
  
      //select database and check selection
      if (!mysql_select_db ("GotA", $con)) {
          die ('Could not select database: ' . mysql_error());
      }
  
  //I have to create this if not it doesnt find the sessions $player_name variable
      $player_name = $_POST['name']; 
  
      //***Create Player Array**//
      $player_info = "SELECT * from players where id = $player_name";
      $player_info2 = mysql_query($player_info) or die ('Couldnt get players name');
      $player_info3 = mysql_fetch_array($player_info2);
  </code></pre>
  
  <p>Well it just seems unsecure to retrive data from the databe using a variable sent with javascript isnt there a way to directly use the variable from the index.php (session part)?
  or is it safe to just pass the information with javascript?</p>