0
我需要連接到特定公司的API,他們提供了一個簡單的API,您可以通過簡單的URL獲取數據。 例如:https://example.com?user=xxx&pass=xxx&data=specificdata有沒有什麼辦法可以防止url注入?
我的問題是:
我有獲取參數,並連接到API函數:
public function urlRequest($base_url, $company_id, $user_name, $password, $parameters) {
if (isset($base_url) && isset($company_id) && isset($user_name) && isset($password) && count($parameters) > 0) {
$url = "https://$base_url?compID=$company_id&user=$user_name&pass=$password&$parameters";
$response = file_get_contents($url);
$response = json_decode($response, true);
return $response;
}
}
1.Is有什麼辦法,我需要從URL注入保護和如果是這樣,哪些功能可以與它相關? (htmlentities等...)
2.哪些字符不能在url中,我需要防範,這是類似於SQL注入?
它不是你的API,你不需要對傳遞給它的變量做任何事情。 –