Warning: fsockopen()

Discussion in 'PHP' started by exinrex, Aug 10, 2007.

  1. #1
    Hey Guys,

    Im very newbie with php. and I dont know what's the problem of it. I used this code to validate the url $fp = fsockopen($parts['host'], 80, $errno, $errstr, 10); on my server and it's working but when I try it to another hosting or server I got this error

    Warning: fsockopen() [function.fsockopen]: unable to connect to www.domain.com:80 (Permission denied)

    Why i got error with the other server? But it's working with my server. Pls help.


    Thank's
     
    exinrex, Aug 10, 2007 IP
  2. exodus

    exodus Well-Known Member

    Messages:
    1,900
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    165
    #2
    What is the code you using? Might be something wrong with the way your calling and placing the varibles in it. -or- it could be your server doesn't allow remote connections. (localhost is not considered remote unless you run it from another server other then the localhost.)
     
    exodus, Aug 10, 2007 IP
  3. exinrex

    exinrex Active Member

    Messages:
    413
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    81
    #3
    Thank's to your reply.

    This is my code.
    function checkURLandConnect($url) {
    if (!preg_match ("/http:\/\/(.*)\.(.*)/i", $url)) {
    return FALSE;
    }
    $parts = parse_url($url);
    $fp = fsockopen($parts['host'], 80, $errno, $errstr, 10);
    if(!$fp) {
    return FALSE;
    }
    fclose($fp);
    return TRUE;
    }

    ok maybe my server doesn't allow remote connections. But how do fix this? thank's
     
    exinrex, Aug 10, 2007 IP
  4. sarav_dude

    sarav_dude Peon

    Messages:
    10
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    check the values are correct that you are providing to the fsockopen.
    
    		  $parts = parse_url($url);
    
    print_r($parts); // check the values are correct that you are providing to the fsockopen.
    
    		  $fp = fsockopen($parts['host'], 80, $errno, $errstr, 10);
    
    PHP:
     
    sarav_dude, Aug 10, 2007 IP