我需要有关如何为 PHP 制作 API 的帮助。我试图让一个 Web 服务器通过 PHP 与另一个 Web 服务器通信。
我还希望它能够更新 MySQL 代码。我正在使用 $_GET
但它不太安全。这是我的代码,您可以看一下吗?
<?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";
?>
最佳答案
这个问题的开放性太大,无法在 StackOverflow 中回答。尝试阅读一些有关 REST 的内容,以及大量有关 PDO 的内容,尤其是在清理用户输入的上下文中。
想想如果有人使用 [url]?command=rm -rf .&password=testing
调用你的 api 会发生什么
关于php - 如何制作一个可以连接mysql的简单api?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31279520/