I have this PHP curl
function to check if a site is online or not:
function check($proc,$url,$keyword,$method,$timeout,$maxredirs) {
// Format Link
$link = $proc."://".$url;
// Agent
$user_agent='Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.130 Safari/537.36';
$options = array(
CURLOPT_CUSTOMREQUEST => $method, //set request type post or get
CURLOPT_POST =>false, //set to GET
CURLOPT_USERAGENT => $user_agent, //set user agent
CURLOPT_RETURNTRANSFER => true, // return web page
CURLOPT_HEADER => false, // don't return headers
CURLOPT_FOLLOWLOCATION => true, // follow redirects
CURLOPT_ENCODING => "", // handle all encodings
CURLOPT_AUTOREFERER => true, // set referer on redirect
CURLOPT_CONNECTTIMEOUT => $timeout, // timeout on connect
CURLOPT_TIMEOUT => $timeout, // timeout on response
CURLOPT_MAXREDIRS => $maxredirs, // stop after 10 redirects
CURLOPT_REFERER => "http://example.com",
CURLOPT_SSL_VERIFYPEER => false,
);
$ch = curl_init( $link );
curl_setopt_array( $ch, $options );
$content = curl_exec( $ch );
$err = curl_errno( $ch );
$errmsg = curl_error( $ch );
$header = curl_getinfo( $ch );
curl_close( $ch );
$header['errno'] = $err;
$header['errmsg'] = $errmsg;
$header['content'] = $content;
// Time (ms)
$totaltime = $header['total_time']*1000;
$totaltime = number_format($totaltime, 0, "", "");
// Handle keyword search
$izkey = 1;
if(!empty($keyword)) {
if (strpos($header['content'],$keyword) !== false) {
$izkey = 1;
}
else {$izkey = 0;}
}
// Return
return $header['http_code']."|".$totaltime."|".$izkey;
}
The function variables are as follow:
$proc
: not user input, will either behttp
orhttps
$url
: user input and will be a full link except thehttp://
orhttps://
part at the beginning$keyword
: user input, just alphanumeric characters$method
: not user input, will beGET
$timeout
: user input, only digits, no more than 60$maxredirs
: user input, only digits, no more than 60
My question is: with the above mentioned user input and returning just 3 variables (see last line of code) is this function safe for the server to run like it is now? Could a user pass a malicious link to harm the server?
I know it may be a silly question, but, I want to be sure. It's better safe than sorry, and it can't hurt to ask.