dounai9294 2015-07-07 21:23
浏览 21
已采纳

如何创建一个可以连接到mysql的简单api? [关闭]

I need help on how to make an API for PHP. I was trying to make one web server communicate with another webserver through PHP.

I also want it to update MySQL code. I was using $_GET but it was less secure. Here is my code, can you please take a look at it?

<?php
/*
example: website-url-here.com/?command=insert-command-here&password=testing
*/
$command = $_GET["command"];
$password = $_GET["password"];
if ($password == "testing") {
//Was not a good idea, less secure.      
//echo eval($command);
//More secure
  if ($command == "create-user")
  {
   //create user command here
  } 
  else if ($command == "delete-user")
  {
   //delete user command here
  } 
  else
  {
  die("Command is incorrect");
  }
}
echo "Success";
?>
  • 写回答

1条回答 默认 最新

  • douqun1977 2015-07-07 21:45
    关注

    This question is way too open ended to answer in a StackOverflow answer. Try reading up a little on REST, and a lot on PDO, especially in the context of sanitizing user input.

    Think about what would happen if somebody called your api with [url]?command=rm -rf .&password=testing

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

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向