SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Evangelist
    Join Date
    Aug 2000
    Location
    Singapore
    Posts
    411
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Reading pages off my domain

    I need to know how to read the content of pages not within my domain, so that my script can auto check if my link exists on my link partners' site. I tried the below but it does not work.

    $filename = "http://www.domain.com";
    $fileopen = fopen($filename, "r");
    $fstring = fread($fileopen, filesize($filename));
    fclose($fileopen);

    Please tell me what's wrong.

  2. #2
    Sidewalking anode's Avatar
    Join Date
    Mar 2001
    Location
    Philadelphia, US
    Posts
    2,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There are a number of issues that are possible. What error did you get?
    TuitionFree a free library for the self-taught
    Anode Says... Blogging For Your Pleasure

  3. #3
    SitePoint Evangelist
    Join Date
    Aug 2000
    Location
    Singapore
    Posts
    411
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Warning: stat failed for http://www.active-gaming.com (errno=2 - No such file or directory) in /home/virtual/site53/fst/var/www/html/check.php on line 5

  4. #4
    SitePoint Enthusiast Powerlord's Avatar
    Join Date
    May 2003
    Location
    Mason, MI, USA
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by FreebieGuy
    Warning: stat failed for http://www.active-gaming.com (errno=2 - No such file or directory) in /home/virtual/site53/fst/var/www/html/check.php on line 5
    From the PHP manual entry for filesize: "Note: This function will not work on remote files as the file to be examined must be accessible via the servers filesystem."
    Ross Bemrose,
    Independant MySQL/Perl/PHP Developer

  5. #5
    SitePoint Evangelist
    Join Date
    Aug 2000
    Location
    Singapore
    Posts
    411
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Then how should I do it?

  6. #6
    Sidewalking anode's Avatar
    Join Date
    Mar 2001
    Location
    Philadelphia, US
    Posts
    2,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you're using PHP 4.3+, just use file_get_contents($url) instead of the whole thing. If not, omit the second argument to fread().
    TuitionFree a free library for the self-taught
    Anode Says... Blogging For Your Pleasure

  7. #7
    SitePoint Evangelist
    Join Date
    Aug 2000
    Location
    Singapore
    Posts
    411
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried omitting the second parameter and I got this:
    Warning: Wrong parameter count for fread() in /home/virtual/site53/fst/var/www/html/check.php on line 5

  8. #8
    Sidewalking anode's Avatar
    Join Date
    Mar 2001
    Location
    Philadelphia, US
    Posts
    2,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oops, I got fread() and fgets() confused. Try
    PHP Code:
    $fileopen fopen($filename"r" );
    $fstring '';
    while(! 
    feof($fileopen)) {
      
    $fstring .= fgets($fileopen);
    }
     
    fclose($fileopen); 
    TuitionFree a free library for the self-taught
    Anode Says... Blogging For Your Pleasure

  9. #9
    SitePoint Evangelist
    Join Date
    Aug 2000
    Location
    Singapore
    Posts
    411
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is it better to do it the fgets() appending way or to assume a filesize that most sites on't go beyond like

    $filename = "http://www.domain.com";
    $fileopen = fopen($filename, "r" );

    $fstring = fread($fileopen, 100000);
    fclose($fileopen);

    I tried it and it works, but I want to know whether the previous way is better or this?


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
  •