tags:

views:

501

answers:

3

i have this link

http://www.bata.com.sg, this website actually exists

that works in my curl code that checks if the page exists.

it works in my localhost code, but it keeps failing in my live website.

I have tested using other domains like http://www.yahoo.com.sg, it works all the time on my localhost AND my live website.

i copied this code http://w-shadow.com/blog/2007/08/02/how-to-check-if-page-exists-with-curl/ word for word.

i dont understand why it fails with this particular url.

my website is hosted with site5.

i noticed that i keep getting false(boolean) for this line

curl_exec($ch);

I get this for curl_error Couldn't resolve host 'www.bata.com.sg'

please advise.

A: 

This might be a firewall issue. sometimes the hosting company might restrict what the webserver can consult.

also can you make sure curl is present in the php_info(). I think you didn't mentioned any error so.

also you get give a try to

file_get_contents('http://www.yahoo.com.sg');
RageZ
first of all its file_get_contentS with a S.secondly, if you looked at the code i copied from it was trying to be as efficient as possible by getting headers rather than the whole file.thirdly, the weird behaving URL in question is NOT www.yahoo.com.sg its www.bata.com.sgfourthly, when i tried file_get_contents on bata.com.sg i get false again on the live website but not on my localhost.
keisimone
thanks for your efforts. i appreciated it. and yes curl is present otherwise it would not work regardless of input
keisimone
Sorry I have edited my post. I suggested to use file_get_contents because it will make an error message, also looking at curl error reporting would help to spot exactly what's happening
RageZ
Couldn't resolve host 'www.bata.com.sg'
keisimone
you have to check the dns settings of your webserver
RageZ
+2  A: 

You need to talk to customer support of site5 to figure out why their server can not resolve www.bata.com.sg

Until you get an answer from them, try the following code.

Key points

  1. It connect to the IP address www.bata.com.sg resolves to - 194.228.50.32
  2. Then sends Host: www.bata.com.sg header

In essence, it works the same way as Curl would if it could resolve the address.

<?php

// this is the IP address that www.bata.com.sg resolves to
$server = '194.228.50.32';
$host   = 'www.bata.com.sg';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $server);

/* set the user agent - might help, doesn't hurt */
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)');
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);


/* try to follow redirects */
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

/* timeout after the specified number of seconds. assuming that this script runs
on a server, 20 seconds should be plenty of time to verify a valid URL.  */
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);


$headers = array();
$headers[] = "Host: $host";

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);

curl_setopt($ch, CURLOPT_VERBOSE, true);

/* don't download the page, just the header (much faster in this case) */
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_HEADER, true);

$response = curl_exec($ch);
curl_close($ch);

var_dump($response);
Anti Veeranna
your code works so that means its the inability to resolve the url that is the problem? but i am not sure if the server IP you gave was the one that www.bata.com.sg correctly resolves to?
keisimone
Yes, its a DNS server problem and since you are using the services of Site5 there is probably nothing you can do about it yourself.And yes, is it the IP for www.bata.com.sg, you can resolve it yourself from command line by doing: nslookup www.bata.com.sg or use any of the web based nslookup services.
Anti Veeranna
thanks anti. the real reason is the nameservers of the bata.com.sghttp://www.intodns.com/bata.com.sg gives an indication.
keisimone
A: 

I have figured out the reason.

Using this website i was told that there was an issue with the nameservers of bata.com.sg

http://www.intodns.com/bata.com.sg

anyway the answers above have been useful as well. i have learned something from them.

keisimone
ok, please accept the answer as well then :)
Anti Veeranna