Вопрос:

Security Issue while using js amcharts with PHP

javascript php amcharts

38 просмотра

1 ответ

3 Репутация автора

Using js amcharts with PHP, Found that source code and paths is accessible through charts. How to block it as this can be serious security issue. I am new to PHP, please elaborate the answer if possible. Thanks

Автор: Rana Источник Размещён: 08.11.2017 11:55

Ответы (1)


0 плюса

23813 Репутация автора

Решение

PHP is a server side language amcharts.js runs on the client, meaning any data it receives must be accessible to the same client that is rendering the chart. You can't make data visible to the cart but invisible to the user, however if you want to limit what the user can see you can render the chart data as JSON in the containing html page (using json_encode) and then pass it as a variable to the charting library, such as:

<script>
  var chart = AmCharts.makeChart("chartdiv", {
   "type": "serial",
   "theme": "light",
   "marginRight": 70,
   "startDuration": 1,
   "graphs": [{
     "balloonText": "<b>[[category]]: [[value]]</b>",
     "fillColorsField": "color",
     "fillAlphas": 0.9,
     "lineAlpha": 0.2,
     "type": "column",
     "valueField": "visits"
   }],
   "chartCursor": {
     "categoryBalloonEnabled": false,
     "cursorAlpha": 0,
     "zoomable": false
   },
   "categoryField": "country",
   "categoryAxis": {
     "gridPosition": "start",
     "labelRotation": 45
   },
   "export": {
     "enabled": true
   }
   "dataProvider": <%php echo json_encode($ResultsArray); %>
  });
</script>
<!-- HTML -->
<div id="chartdiv"></div>
Автор: Jason Sperske Размещён: 09.11.2017 12:02
32x32