Hello guys
I know how to copy the contents of a site through curl
but how can i know the ip through the curl ?
| SitePoint Sponsor |
Hello guys
I know how to copy the contents of a site through curl
but how can i know the ip through the curl ?
Could gethostbyname() help you? http://uk3.php.net/gethostbyname




As far as I know you can't. Use gethostbyname() instead.
Pawel Decowski (you should follow me on Twitter)
hmm no curl ?
ok i try gethostbyname()
and save it to the database
but he don't execute ?
when i use it like that
$ip = gethostbyname($site);
after that
insert $ip in the database
but the $ip value was empty
up for help


If you post your code you will have a better chance of recieving help.
ok man
PHP Code:$curl_opts = array(CURLOPT_URL => $url,
CURLOPT_NOBODY => true,
CURLOPT_HEADER => true,
CURLOPT_RETURNTRANSFER => true);
$ch = curl_init();
curl_setopt_array($ch, $curl_opts);
$doc = curl_exec($ch);
curl_close($ch);
$ip = gethostbyname($url);
insert $ip in the database


Before the insert add something like die($ip); and see if it contains a value.
What type of field is set for the ip in the DB?


What is the value of $ip after the test? If it has a value then the issue lies in the type of field in the DB you have created for it.


Post the code for your insert statement. Perhaps the issue lies in there.


Try this and see what is says.
PHP Code:$ins = mysql_query("INSERT INTO digg (id, url,ip)
VALUES('', '$url','$ip') ");
if (!$ins) {
die('Invalid query: ' . mysql_error());
}
not works
PHP Code:$curl_opts = array(CURLOPT_URL => $url,
CURLOPT_NOBODY => true,
CURLOPT_HEADER => true,
CURLOPT_RETURNTRANSFER => true);
$ch = curl_init();
curl_setopt_array($ch, $curl_opts);
$doc = curl_exec($ch);
curl_close($ch);
$ip = gethostbyname($url);
$ins = mysql_query("INSERT INTO digg (id, url,ip)
VALUES('', '$url','$ip') ");
if (!$ins) {
die('Invalid query: ' . mysql_error());
}
the value in the database
url
http://www.google.com
ip
http://www.google.com
I think the reason it had not been implemented


Well according to the manual it returns the string it was fed on failure. For some reason. It seems to be failing.
i don't think this is the problem
because it's works like that
$ip = gethostbyname('www.example.com');
but did not works like that
$ip = gethostbyname($url);
I think the reason it had not been implemented
Try gethostbyname() on the URL without the http:// protocol bit in front
$url = 'www.google.com';
$ip = gethostbyname($url);
Bookmarks