I want to get page status code.
Url address has a port and after that alias:
http://93.184.216.xxx:3000/status
I tried this this:
function status($url) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, true); // we want headers
curl_setopt($ch, CURLOPT_NOBODY, true); // we don't need body
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT,10);
$output = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpcode == 200) { return '<span class="green-link">ONLINE</span>';}
else {
return '<span class="red-link">'.$httpcode.'</span>';}
}
But this is useless, I'm always get status 0.
Can anybody have better idea?
Thanks
Related
I am trying to update a LEAD using this URL
$lead_url = ‘https://’.$company_domain.’.pipedrive.com/api/v1/leads/’ . $leadID . ‘?api_token=’ . $PD_API_KEY;
But it returns 404 Not Found. When I check this URL in the browser it returns the complete information of that lead.
Here is my Curl Code:
function pipedrive_update_curl($arr , $endpoint)
{
$response = array();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $endpoint);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($arr));
//***//
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
//**//
$response_result = curl_exec($ch);
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$curl_errors = curl_error($ch);
curl_close($ch);
$response['error'] = $curl_errors;
$response['status'] = $status_code;
$response['response'] = $response_result;
return $response;
}
Can somebody please explain where I am going wrong?
PUT method for updating leads is not supported.
see docs and pipedrive community posts:
https://developers.pipedrive.com/docs/api/v1/Leads#updateLead
https://devcommunity.pipedrive.com/t/put-not-working-when-updating-a-lead/3629
I am trying to create a script that should check all indexed pages from Google. But it will not give proper output.
<?php
function indexed($url) {
$url = 'http://webcache.googleusercontent.com/search?q=cache:' . urlencode($url);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Chrome 10');
if (!curl_exec($ch)) {
// var_dump('failed');
return false;
}
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
//var_dump($code);
return $code == '200';
}
echo indexed('http://www.berlin-info.de/de/tourist-info/urlaub-in-kanada');
?>
I'm writing a script which checks an array of domain names using curl and returns their http codes.
$urls = array('http://www.example.com', 'http://www.example2.com', 'http://www.example3.com');
$msg = "
<p><strong>URL Error Check</strong></p>
";
//Set code colours
$code200 = '<span style="color: green;"> OK - ';
$code0 = '<span style="color: red;"> Undefined Error - ';
$code404 = '<span style="color: red;"> File Not Found - ';
foreach($urls as $value){
$ch = curl_init($value);
curl_setopt($ch, CURLOPT_HEADER, true); // we want headers
curl_setopt($ch, CURLOPT_NOBODY, true); // we don't need body
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT,10);
curl_setopt($ch, CURLOPT_CERTINFO,true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 5);
$output = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if($httpcode==301 || $httpcode==302){
$redirect = curl_getinfo($ch, CURLINFO_REDIRECT_URL);
$httpcode .='<br> Redirects to: <span style="color: orange;">'.$redirect;
}
curl_close($ch);
$msg .= $value.": <strong>".${code.$httpcode}.$httpcode."</strong></span><br><br>";
}
echo $msg;
When the code is 301 or 302 it returns the resolving url after the redirect. I'd like it to then check the final URL and return it's http code as well.
Can someone please suggest how I can do this?
you can use this option for your curl-request:
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
With this option set to true, your request will not stop when a redirect occurs.
I want to use VirusTotal as way that they wrote in their websites.
<?php
$virustotal_api_key = '9491e275f708f55b0777b495411556c916afdda7255d4614500d4aed27175001';
$scan_url = 'https://www.google.com/';
$post = array('apikey' => $virustotal_api_key,'url'=> $scan_url);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.virustotal.com/vtapi/v2/url/scan');
curl_setopt($ch, CURLOPT_POST, True);
curl_setopt($ch, CURLOPT_VERBOSE, 1); // remove this if your not debugging
curl_setopt($ch, CURLOPT_RETURNTRANSFER ,True);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$result=curl_exec ($ch);
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
print("status = $status_code\n");
if ($status_code == 200) { // OK
$js = json_decode($result, true);
print_r($js);
} else { // Error occured
print($result);
}
curl_close ($ch);
?>
But I always return error as:
status = 0
I have been searching a lot and still found nothing!!!
I very appreciate if u help me out.
tnx.
I have figured out what was the problem.
This is because thier website banned my country(Iran) IPs.
I wasted my time from morning to noon to found this out :( :(
I should search for something else like this.
I try to get the content of this website with cURL
www.mytischtennis.de/public/
but it gets no body response. With many other websites the code works:
<?php
$output = grabPage(
"http://www.mytischtennis.de/public/"
//"http://www.spiegel.de" //this page and many other pages are working
);
if (is_array($output)) {
var_dump($output);
} else {
echo $output;
}
function grabPage($url)
{
$ch = curl_init();
$cookiePath= dirname(__FILE__) . "\cookie.txt";
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_MAXREDIRS, 50);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_TIMEOUT, 40);
curl_setopt($ch, CURLOPT_COOKIE, 'CFID=c7a592d8-5798-4471-9af4-4c4d954d03cd; cfid=c7a592d8-5798-4471-9af4-4c4d954d03cd; MYTT_COOKIESOK=1; CFTOKEN0=; cftoken=0; SRV=74');
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiePath);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiePath);
$fpErrors = fopen(dirname(__FILE__) . '\errorlog.txt', 'w');
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_STDERR, $fpErrors);
curl_setopt($ch, CURLOPT_URL, $url);
ob_start();
$curl_exec = curl_exec($ch);
ob_end_clean();
if ($curl_exec === false) {
echo 'Error: ' . curl_error($ch);
} else {
echo 'Success';
}
var_dump(curl_getinfo($ch));
curl_close($ch);
return $curl_exec;
}
I tried to read a fiddler/wireshark dump of a browser request to this website. But I can't figure out which of that many requests and which parameters are necessary to get the content.
You can test cURL with the url www.mytischtennis.de/public/ also on this website:
http://onlinecurl.com/
You need to accept gzip encoding in the response by sending the appropriate HTTP header in the request:
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept-Encoding: gzip'));
Now your answer from the server might or might not be gziped. The proper way to check that is to interpret the Content-Encoding HTTP header in the response. But you can also do it quick and dirty like this:
$content = #gzdecode($curl_exec);
return $content !== false ? $content : $curl_exec;