Sockets

Discussion in 'PHP' started by Danago, Jan 30, 2007.

  1. #1
    --------------------------------------------------------------------------------

    Hi. Sockets are one thing im very inexperienced with. Ive never had a need to use them, until now.

    For now, all i need to do is connect to www.example.com and store the page source/html of /index.php into a $variable.

    I tried using fsockopen() to connect to www.example.com through port 80, and then just did something with fgets(). Anyway, whatever i did, it was wrong, and didnt work. Soooo...anyone able to guide me in the right direction?

    Thanks in advance for the help :)

    Dan.
     
    Danago, Jan 30, 2007 IP
  2. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #2
    http://de2.php.net/file_get_contents
    $theurl="http://www.site.com/";
    $filestring=file_get_contents("$theurl") ;
    PHP:
    Your host might have disabled it though. Check with them if it fails.
     
    mad4, Jan 30, 2007 IP
  3. Dan Nilsson

    Dan Nilsson Peon

    Messages:
    72
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I would suggest cURL, if your host supports it.

    http://se.php.net/manual/en/ref.curl.php

    From the comments on above page:
    
    <?php
    $url="http://anything";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    $content = curl_exec ($ch); # This returns HTML
    curl_close ($ch); 
    ?>
    
    PHP:
     
    Dan Nilsson, Jan 30, 2007 IP