我想爲我正在處理的事情做API,但我無法弄清楚如何解決現在有的事情。XSS&SQLi Prevention +從URL中獲取變量
我想有像登錄,如果關鍵的是正確的和匹配數據庫中的IP,然後做其他事情
if (isset($_GET['key'])) {
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
$apikey = $_GET['key'];
//$apikey = mysql_real_escape_string($api);
echo $apikey."<br />".$ip;
$mysql_host = "**.***.**.***";
$mysql_database = "*****";
$mysql_user = "********";
$mysql_password = "******************";
mysql_connect($mysql_host,$mysql_user,$mysql_password);
@mysql_select_db($mysql_database) or die("Unable to select database");
$query="SELECT * FROM `api` WHERE `apikey` = '".$apikey."' AND `ip`='".$ip"'";
$result=mysql_query($query);
if (!$result) {
die(mysql_error());
}
// assign mySQL values from table to php variables
$teest = mysql_result($result,1,'apikey');
echo $teest;
//close the mySQL connection
mysql_close();
} else {
echo "Usage: api.php?key={YourUniqueKey}";
}
使用'mysql_num_rows()' – 2014-10-31 15:34:27