HEY KEN!!!!

On Tue, Aug 12, 2003 at 09:30:21PM -0500, Ken wrote:

> I imagine I would want to form a basic get header request, with URL,
> whatever else I need, and a "Range:bytes=1000-2000" header.  If I
> understand correctly, the (HTTP/1.1) web server would return the 
> document I want, just bytes 1000-2000.

I hadn't heard of that option in HTTP 1.1, but that's because I haven't
looked.  Interesting.  Anyway, if you are certain the information will
always be at the same byte locations, then your approach will work.  So, 
in this case you can do something similar to the post to host scripts I 
mentioned earlier this evening.

    $Host   = 'www.foo.com';
    $Script = 'test.bin';
    $Return = '';

    if ($sp = fsockopen($Host, '80')) {
        fputs($sp, "POST $Script HTTP/1.1\n");
        fputs($sp, "Host: $Host\n");

        /*
         * THESE NEXT TWO LINES ARE FROM A POST-TO-HOST SCRIPT.
         * MODIFY THEM TO FIT YOUR NEEDS, LIKE SWITCHING THEM
         * TO YOUR "Range: bytes=1000-2000\n" HEADER.
         */
        fputs($sp, "Content-type: application/x-www-form-urlencoded\n");
        fputs($sp, 'Content-length: ' . strlen($Post) . "\n");

        fputs($sp, "Connection: close\n\n");

        while ( !feof($sp) ) {
            $Return .= fgets($sp, 2000);
        }
        fclose($sp);

    } else {
        $Return = '<p>NO DICE!</p>';
    }

    echo $Return;

If that's the approach you use, post back here with the tweaked two lines 
that made it work.

BUT, if the information/byte locations may change, then you'll want to
grab the page with readfile() and then use regular expressions to find the
stuff you want to keep.


> I realize it might be simpler to do a file read (assuming I'm doing this
> on the very same server as the document)

You don't need to be on the same server.  PHP's file reading functions are 
all internet aware.  http:// and ftp:// are legit.

Hope things are well for you out there in the Lone Star State,

--Dan

-- 
     FREE scripts that make web and database programming easier
           http://www.analysisandsolutions.com/software/
 T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
 4015 7th Ave #4AJ, Brooklyn NY    v: 718-854-0335   f: 718-854-0409

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to