douzhun8615 2015-10-09 17:06
浏览 30
已采纳

现场网站相当安全?

I wanted to know if something like the following would be fairly secure and okay to use in a production setting. I am retrieving data from a database and using the response data into a graph using Chart.js.

My html file

<div id="canvas-holder">
    <canvas id="chart-area2" width="200" height="200" />
</div>

<div id="canvas-holder">
    <canvas id="chart-area" width="200" height="200" />
</div>

<div id="chartjs-tooltip"></div>


<script>
$.ajax({
   url: 'chartpi.php',
   success: function (response) {//response is value returned from php 
        var datachart = JSON.parse(response);
        var ctx2 = document.getElementById("chart-area2").getContext("2d");
        window.myPie = new Chart(ctx2).Pie(datachart);
   }
});

$.ajax({
   url: 'chartpi2.php',
   success: function (response) {//response is value returned from php
        var datachart = JSON.parse(response);
        var ctx = document.getElementById("chart-area").getContext("2d");
        window.myPie = new Chart(ctx).Doughnut(datachart);
   }
});
</script>

My PHP file

<?php

        // set up the connection variables
        $db_name  = '$dbname';
        $hostname = '$host';
        $username = '$uname';
        $password = '$pass';

        // connect to the database
        $dbh = new PDO("mysql:host=$hostname;dbname=$db_name", $username, $password);

        // a query get all the records from the users table
        $sql = 'SELECT * FROM pichart2';

        // use prepared statements, even if not strictly required is good practice
        $stmt = $dbh->prepare( $sql );

        // execute the query
        $stmt->execute();

        // fetch the results into an array
        $result = $stmt->fetchAll( PDO::FETCH_ASSOC );

        // convert to json
        $json = json_encode( $result );

        // echo the json string
        echo $json;
?>
  • 写回答

1条回答 默认 最新

  • duanpanyang1962 2015-10-09 17:51
    关注

    Your question of

    would be fairly secure and okay to use in a production setting

    The two obvious area's you have covered

    • parameterized queries on the backend
    • the data being retrieved is not based on user input from this site page

    However, I will caution that if any of the data being retrieved from the piechart table(s) retains any user provided data from some other source, that you should consider/implement the proper output encoding even if proper input sanitation was performed.

    If that isn't the case, then no worry there.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow