Results 1 to 22 of 22

Thread: Grab Source, AGAIN!

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2004
    Posts
    11

    Question Grab Source, AGAIN!

    I know this is probly has been covered many times, but what code can I use to grab a HTTP document and shove it into a variable?

    Or is this not possible with PHP? then Javascript?

    Is There No Way?
    Last edited by x198; Jan 10th, 2004 at 01:55 PM.

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629
    Try this:

    Code:
    <?
      $open = fopen("http://www.complex-sys.com/source/leetprogramming/index.php", "r"); //request file via HTTP
      $size = 1500; //size in KB
      $read = fread($open, $size * 1024); //store HTTP request in $read
      fclose($open);
    ?>
    When using fread, you might have to adjust the filesize parameter ($size).. it only reads 1.5MB in that example, but I'm betting that will be enough reading, although it might not be depending on whatever you are opening.. Anyway, that should get you started.
    Like Archer? Check out some Sterling Archer quotes.

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2004
    Posts
    11

    ah

    I think i need CGI for what I'm doing...

    When i have it say 'echo $open' it just says 'resource id #1' how might i be able to display it in this way?

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    echo $read;
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5

    Thread Starter
    New Member
    Join Date
    Jan 2004
    Posts
    11
    yesssssssss!

    TYSM!

    -Resolved

  6. #6

    Thread Starter
    New Member
    Join Date
    Jan 2004
    Posts
    11
    Isn't there some limitation by PHP on how big a string can be?

    I'm now having problems with 'Large' strings...

  7. #7
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Probably. No string can be larger than ~1.8 gigs on Windows, I think a little more in Linux. But PHP likely imposes more restrictions.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  8. #8

    Thread Starter
    New Member
    Join Date
    Jan 2004
    Posts
    11
    why is it cutting off half way through the web document? i'm guessing at the 1500KB mark...

  9. #9
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Because the original code you have reads only 1500 KB.

    Make a smaller buffer, read a block and write it out.
    Code:
    <?
      $open = fopen("http://www.complex-sys.com/source/leetprogramming/index.php", "r"); //request file via HTTP
      while(($read = fread($open, 4096)) {
        echo $read;
      }
      fclose($open);
    ?>
    This should write out everything, no matter how large, in blocks of 4 KB.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  10. #10

    Thread Starter
    New Member
    Join Date
    Jan 2004
    Posts
    11
    Sorry to annoy again but
    Code:
    <?
      $open = fopen("http://www.complex-sys.com/source/leetprogramming/index.php", "r"); //request file via HTTP
      while($read = fread($open, 4096)) { //u could see it 2 ways, either you had an extra ) or one needed to be removed, *Fixed*
        echo $read;
      }
      fclose($open);
      
    ?>
    doesnt work...least for me.
    Last edited by x198; Jan 10th, 2004 at 06:46 PM.

  11. #11
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    You might have to change something about the while loop. Read up on file I/O, you should find the solution.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  12. #12

    Thread Starter
    New Member
    Join Date
    Jan 2004
    Posts
    11
    u excluded a ')'

  13. #13
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Don't blame me, it's 1AM here
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  14. #14

    Thread Starter
    New Member
    Join Date
    Jan 2004
    Posts
    11
    It's the codes fault, it should have know about your inaccuracy!

    6:50PM Eastern

  15. #15

    Thread Starter
    New Member
    Join Date
    Jan 2004
    Posts
    11
    One more thing...

    I wanted to use a variable for the site name, and this is what doesnt work
    Code:
    $sitenam="http://www.thegh.org";
    
      $open = fopen($sitenam, "r");
    NM stupid me forgot a ';' and PHP had a spaz attack
    Last edited by x198; Jan 10th, 2004 at 07:00 PM.

  16. #16
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    What error?
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  17. #17

    Thread Starter
    New Member
    Join Date
    Jan 2004
    Posts
    11
    Another error...

    Code:
    $sitenam="www.google.com"; //any random site
    
    						
      $open = fopen($sitenam, "r"); 
      		//Open the site
      while(($read = fread($open, 4096))) { //Open 4096bytes, or 4KB
        echo ($read); //4KB onto the Client page, then go back for your brothers!
      }
      fclose($open);
    why cant i do this?

    Says:
    Warning: fopen(www.google.com): failed to open stream: No such file or directory in v2.php on line 13
    Warning: fread(): supplied argument is not a valid stream resource in v2.php on line 15
    Warning: fclose(): supplied argument is not a valid stream resource in v2.php on line 18

    $sitenam is going to be a form variable if i can get it working
    Last edited by x198; Jan 10th, 2004 at 09:34 PM.

  18. #18
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    The site name must start with http://
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  19. #19
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629
    If you're grabbing the site name from a form and are worried about people entering in "http://" and don't want to prefix it yourself, try this:

    PHP Code:
    <?
      function checkURL($url){
        if(!substr($url, 0, 7) == "http://"){
          return "http://" . $url;
        }
      }

      //used like so:
        $sitenam = checkURL($_POST['site']);
    ?>
    It should work..
    Like Archer? Check out some Sterling Archer quotes.

  20. #20

    Thread Starter
    New Member
    Join Date
    Jan 2004
    Posts
    11
    Too many functions, AHHHH... ok, i'll try to use it, TY.

    Right now i'm having trouble using this ban list at:
    http://tutorials.programmingsite.co.uk/banwords.php

    i put the word 'ass' into the block list, and it blocks 'glass'

    so i try using $addspace = (" ".$word); and i starts to ignore the function all together, i'm guessing, because it cant find the $word list.

  21. #21
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629
    if you want to do filter things at all you're going to be suffering quality.. if you block out just "ass", then it will filter things like glass, to make it "gl***", but if you just block out the word ass, like (" ass "), or something like that, whats going to stop someone from doing asss? you're gonna have to figure out what you want to filter out..

    also, it would probably be easier to read if you posted the exact code you were using, and not just a link to a site with a copy of the code.. I'm guessing you changed something about it.

    either live with it, or don't use a word filter..
    Like Archer? Check out some Sterling Archer quotes.

  22. #22
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    The best way to do word filters is to use preg_replace() and regular expressions. That's the most efficient way.

    Edit: Search these forums for examples. I've answered quite a few threads about it.
    My evil laugh has a squeak in it.

    kristopherwilson.com

Posting Permissions

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



Click Here to Expand Forum to Full Width