-1

I want to send the content of a $_SESSION to a php page linked by a Javascript script:

the code I'm working with is:

<?php
   error_reporting(0);
   session_start();
   include("connect.php");

   $query="SELECT id,name... FROM users WHERE ...";
   $result= mysql_query($query) or die ($query);

   while($row=mysql_fetch_array($result))
   {
    ...
    $_SESSION['user_id']=$row[mysql_field_name($result,3)];
    ...
   }

  echo
  "
   <div id='chartdiv' style='width: 100%; height: 500px;'></div>
      <script>
       var chart = AmCharts.makeChart( 'chartdiv', 
       {
        'type': 'serial',
        'dataLoader': 
        {
         'url': 'dataLastSevenDays.php'
        },

        'pathToImages': 'http://www.amcharts.com/lib/images/',
        'categoryField': 'category',
        'dataDateFormat': 'YYYY-MM-DD',
        'startDuration': 1,
        'categoryAxis': 
        {
         'parseDates': true
        },
        'graphs': 
        [ 
         {'valueField': 'value1','bullet': 'round','bulletBorderColor': '#FFFFFF','bulletBorderThickness': 2,'lineThickness ': 2,'lineAlpha': 0.5}, 
        ]
       } );
   </script>
  ";

Now, I want to send the content of $_SESSION['user_id'] to the "dataLastSevenDays.php" page (which is actually contained in the JS script), but I can't figure out how it can be done.

I need to send the content of $_SESSION['user_id'] to that page because it actually contains the Query that draws the chart

gigapico00
  • 417
  • 1
  • 7
  • 24

1 Answers1

0

You should be able to do something like this:

<script>
    var userId = "<?php echo $_SESSION['user_id']; ?>";
    console.log(userId);
</script>
Chris
  • 1,180
  • 1
  • 9
  • 17
  • 1
    And OP is now vulnerable to XSS. – PeeHaa Jan 25 '16 at 21:54
  • Thank you Chris, and then the $_SESSION variable will be available inside the "dataLastSevenDays.php" page? Sorry but I'm not at home now and so I cannot try if this works – gigapico00 Jan 26 '16 at 07:04