SitePoint Sponsor

User Tag List

Results 1 to 19 of 19
  1. #1
    SitePoint Member
    Join Date
    Oct 2008
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how can i know the ip through the curl ?

    Hello guys

    I know how to copy the contents of a site through curl

    but how can i know the ip through the curl ?

  2. #2
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Location
    Hailsham, UK
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Could gethostbyname() help you? http://uk3.php.net/gethostbyname

  3. #3
    Web Professional
    Join Date
    Oct 2008
    Location
    London
    Posts
    862
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As far as I know you can't. Use gethostbyname() instead.

  4. #4
    SitePoint Member
    Join Date
    Oct 2008
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  5. #5
    SitePoint Member
    Join Date
    Oct 2008
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    up for help

  6. #6
    SitePoint Addict Robert_2006's Avatar
    Join Date
    Jun 2006
    Location
    Tarpon Springs Fl.
    Posts
    265
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you post your code you will have a better chance of recieving help.

  7. #7
    SitePoint Member
    Join Date
    Oct 2008
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Robert_2006 View Post
    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 

  8. #8
    SitePoint Addict Robert_2006's Avatar
    Join Date
    Jun 2006
    Location
    Tarpon Springs Fl.
    Posts
    265
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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?

  9. #9
    SitePoint Member
    Join Date
    Oct 2008
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Robert_2006 View Post
    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?
    i test it like that

    $ip = gethostbyname('www.example.com');

    works good ?

  10. #10
    SitePoint Addict Robert_2006's Avatar
    Join Date
    Jun 2006
    Location
    Tarpon Springs Fl.
    Posts
    265
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  11. #11
    SitePoint Member
    Join Date
    Oct 2008
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Robert_2006 View Post
    What is the value of $ip after the test?
    the site ip > 209.85.135.104 < google


    Quote Originally Posted by Robert_2006 View Post
    If it has a value then the issue lies in the type of field in the DB you have created for it.
    the type varchar ?

  12. #12
    SitePoint Addict Robert_2006's Avatar
    Join Date
    Jun 2006
    Location
    Tarpon Springs Fl.
    Posts
    265
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Post the code for your insert statement. Perhaps the issue lies in there.

  13. #13
    SitePoint Member
    Join Date
    Oct 2008
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Robert_2006 View Post
    Post the code for your insert statement. Perhaps the issue lies in there.
    that

    $ins = mysql_query("INSERT INTO digg (id, url,ip)
    VALUES('', '$url','$ip') ");

  14. #14
    SitePoint Addict Robert_2006's Avatar
    Join Date
    Jun 2006
    Location
    Tarpon Springs Fl.
    Posts
    265
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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());


  15. #15
    SitePoint Member
    Join Date
    Oct 2008
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  16. #16
    SitePoint Addict Robert_2006's Avatar
    Join Date
    Jun 2006
    Location
    Tarpon Springs Fl.
    Posts
    265
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well according to the manual it returns the string it was fed on failure. For some reason. It seems to be failing.

  17. #17
    SitePoint Member
    Join Date
    Oct 2008
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  18. #18
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Location
    Hailsham, UK
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try gethostbyname() on the URL without the http:// protocol bit in front
    $url = 'www.google.com';
    $ip = gethostbyname($url);

  19. #19
    SitePoint Member
    Join Date
    Oct 2008
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by calkie_f View Post
    Try gethostbyname() on the URL without the http:// protocol bit in front
    $url = 'www.google.com';
    $ip = gethostbyname($url);
    works good

    thanks all

    and about the function

    i think the ( allow_url_fopen ) must be on ?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •