I am using the following code to see if a video is ready to embed on my site. It exits if the video is a 404 page and continues if it is anything else, including a video of course. Well, in theory.
I was confused for like an hour why it stopped working but it must be because the video is ready now and my code is trying to include the whole video in my code rather than just getting a header or something.
Is there a better way to do it please??
$url=$videourl;
$handle = curl_init($url);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE);
/* Get the HTML or whatever is linked in $url. */
$response = curl_exec($handle);
/* Check for 404 (file not found). */
$httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
if($httpCode == 404) {
exit("video not ready!");
}
curl_close($handle);
It sound like you want to make a HEAD request. Use:
curl_setopt($handle, CURLOPT_NOBODY, true);
Related
I am writing a php code to trace ulr redirects using cUrl but is badly stuck on one point
What i do is take urls in an array , pass it to function and gets redirect links but with one of the url
"https://c.duomai.com/track.php?site_id=264419&aid=4598&euid=220520a5217713c8ee56ed&t=https%3A%2F%2Fwww.samsclub.com%2F"
when i send it as first item in array cUrl goes to right webpage and finds url but when this url is at any other location then first item in row it treats this url differently and gives error page ,
i have tried url encoding , removed white space everything but nothing is helping
code :
$handle = curl_init($url);
curl_setopt($handle, CURLOPT_HEADER, TRUE);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($handle, CURLOPT_USERAGENT, $user_agent);
$response = curl_exec($handle);
$httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
$newquery_get = htmlentities($response);
curl_close($handle);
My problem is
I have made curl request on paxfull api earlier it was returning result but now its returning 503 .
Here is my code
$handle = curl_init();
curl_setopt($handle, CURLOPT_URL, 'https://paxful.com/buy-bitcoin?format=json');
curl_setopt($handle, CURLOPT_POST, false);
curl_setopt($handle, CURLOPT_BINARYTRANSFER, false);
curl_setopt($handle, CURLOPT_HEADER, true);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_CONNECTTIMEOUT, 10);
$response = curl_exec($handle);
$hlength = curl_getinfo($handle, CURLINFO_HEADER_SIZE);
$httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
$body = substr($response, $hlength);
// If HTTP response is not 200, throw exception
if ($httpCode != 200) {
throw new Exception($httpCode);
}
I get this error:
Error Fatal error: Uncaught exception 'Exception' with message '503'
I googled and found it might be ip address blocked but when made get request at browser its giving results to me.
now i came with conclusion they are not allowing any GET Request .
if you run url https://paxful.com/buy-bitcoin?format=json it first check browser the return the result.
how can we get results of paxfull api. please suggest
here is snapshot
then there api redirects 404
url http://localhost/cdn-cgi/l/chk_jschl?jschl_vc=c5b74eae14eb1b1e5862f913b9f0f178&pass=1499953121.017-h%2FljgkjMr%2B&jschl_answer=18913
Its not possible through javascript also
fiddle http://jsfiddle.net/00cvyyuo/350/
i found link How to bypass cloudflare bot/ddos protection in Scrapy?
but this link helps in python so can someone help in php or javascript.
try to use Chrome's network tab in Developer Tools(f12) to see the actual request being sent. If it works then try to repeat the request from a REST client, where you can edit the headers to check what works and what not.
If you got it working then set all the headers in cURL. If it fails then set verbose and check what was sent.
I am using curl in the Google App Engine (GAE) environment. My code simplified is as follows
$url = 'https://img.youtube.com/vi/rzuYnQwD840/0.jpg';
$handle = curl_init($url);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE);
$response = curl_exec($handle);
$httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
As long as $url is valid, one would expect $httpCode to be 200. This is what I get testing this code locally. This code was also working last month on GAE in production last month when it was pushed. Today we noticed that $httpCode is now coming up as 0 on GAE. Is there some way to fix this? I just need to test if the response to a URL request is 200.
Update: It looks like the issue is limited to YouTube? There doesn't appear to be a problem with Vimeo (e.g. $url = https://vimeo.com/api/v2/video/149497499.json';).
First Method:
Replace $url with 'http://img.youtube.com/vi/rzuYnQwD840/0.jpg';
This problem occurs due to SSL. You are hitting a secure URL.
Second Method:
Use the following code:
$url = 'https://img.youtube.com/vi/rzuYnQwD840/0.jpg';
$handle = curl_init($url);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec($handle);
$httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
So I found the answer I was looking for in another GAE question (PHP's Curl not working on AppEngine). Within the php.ini file in the base directory of the application, add the following:
google_app_engine.enable_curl_lite = "1"
I'm using Apache for local development, but if you're using GAE locally then add the following
extension = "curl.so"
NB You can only have one of these in you php.ini file at a time. It will ignore whichever one comes second.
i am trying to execute a link (without page being redirected) using curl.
see below my code...
$ch = curl_init(); // Initializing
//curl_setopt($ch, CURLOPT_URL, trim("http://api.smsgatewayhub.com/smsapi/pushsms.aspx?user=stthomasmtc&pwd=429944&to=9176411081&sid=STMTSC&msg=Dear Sam,%20choir%20practice%20will%20be%20held%20in%20our%20Church%20on%20July%2031%20at%208:00%20pm.%20Thanks,%20St.%20Thomas%20MTC!&fl=0&gwid=2")); // Set URI
curl_setopt($ch, CURLOPT_URL,"http://api.smsgatewayhub.com/smsapi/pushsms.aspx?user=stthomasmtc&pwd=429944&to=9176411081&sid=STMTSC&msg=Dear Sam,%20choir%20practice%20will%20be%20held%20in%20our%20Church%20on%20July%2031%20at%208:00%20pm.%20Thanks,%20St.%20Thomas%20MTC!&fl=0&gwid=2"); // Set URI
curl_setopt($ch, CURLOPT_HEADER, 0); //Set Header
curl_setopt($ch, CURLOPT_TIMEOUT, 300); // Time-out in seconds
$result = curl_exec($ch); // Executing
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($httpCode != 200) {
$result = ""; // Executing
}
curl_close($ch); // Closing the channel
return $result;
but i get the response as Bad Request.
when i try to change the url to www.google.com, it seems executing. When i manually use this link in browser, its executed as expected - to send message to me. let me know if there is a better way to execute a link without page being redirected...
This maybe a very old question. But since it has gone unanswered and pops up in Google when you say SMSGatewayHub + SO, I'll go ahead and present an alternative.
Get the class https://github.com/adarshdec23/SMSGatewayhub. It works with both promotional and transactional SMS messages.
Here is a step by step guide to using it.
It uses an API key instead of your username and password. Once you're done with that, the class makes an API call (without cURL). Its simple and gets the job done.
I am trying to retrieve the status of the url. I am writing php code to retrieve it but i am not getting the output. Nothing is being displayed.
I am reading the url's from the xml file and storing it in variable. I am doing
file_get_contents($url);
echo $http_respone_header[0];
$url contains the url which i have read from the xml file.
The thing You are doing is not getting URL status but content of the site. In case of wrong/invalid URL file_get_contents() returns false as it is described in documentation in here
If You are trying to get status You can simply use the solution described in other topic on this site.
<?php
$url = 'http://www.wp.pl';
$handle = curl_init($url);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE);
/* Get the HTML or whatever is linked in $url. */
$response = curl_exec($handle);
/* Check for 404 (file not found). */
$httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
echo $httpCode;
curl_close($handle);
?>
Link to the mentioned topic: here