dongzhan1948 2013-08-01 19:34
浏览 40

json,ajax,php和mySQL的设计结构

I have a new project coming up, and I would like to use ajax to get the mysql result (in json format) so that I can use jQuery ajax to display it properly. Since I'm really new to json, ajax, jquery please tell me if my design structure is okay or not and if there is any security issue.

Here is my design:

Core.class.php - it will use the PDO object to connect to the mySQL database, and it will do some queries and return the results

json.php - it will create a singleton core obj and return the result in json format, based on the querystring data. ie.

if ($_GET['get_type'] == 'employeeinfo')
{
    return get_all_employee_info(); // and in this function I'll use the core to do query and echo all employee data in json format
}
else if ($_GET['get_type'] == 'companyinfo')
{
    return get_all_company_info(); // and in this function I'll use the core to do query and echo all company data in json format
}

...

index.php - it will use:

$.ajax ( {
    url: 'json.php',
    data: //getdata type,
    success: function(results) { //use results to populate data and display on this page }

});

to load data and display in result HTML format.

Also, user will have to login first in order to load index.php, and once logged in successfully, session will be created.

So in index.php and json.php, I'm going to check the session, if failed, will throw the die() method.

so is my design structure okay? is there any security issue?

  • 写回答

4条回答 默认 最新

  • drxm72811 2013-08-01 19:44
    关注

    Here are some tips:

    1. Don't return your database objects directly using json, as this would potentially expose your database structure. Simplify your data before return it (don't return more data then you need)

    2. Use a JS template engine for rendering the data. Some examples: https://github.com/justjohn/twig.js/wiki http://twitter.github.io/hogan.js/

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算