HELP: strange php behavior downloading html

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Kimmo Laine wrote:
Quoted text here. Click to load it

Unless next_page.php generates PHP, the script with this include will
only get HTML.

Quoted text here. Click to load it


    if (isset($_GET['foo'])) {
      echo '<?php echo $_GET[\'foo\']; ?>';
    } else {
      echo '<?php echo \'Not available\'; ?>';

File not found: (R)esume, (R)etry, (R)erun, (R)eturn, (R)eboot

Re: HELP: strange php behavior downloading html

Thanks Rik for pointing out that the HTTP headers on that redirected
page were setting and using cookies and for pointing me in the right
direction with cURL.

I was able to yield a correctly working result for my HTML downloading
problem in less than an hour, using cURL with PHP.

With the function I have below, I just call tempnam() to give me a
temporary filename, call my function with the uri and the results from
tempnam(), and then read the file with file_get_contents().  I then can
delete the file with unlink().

Here is the function I wrote to download a uri into a file (following
all redirects, ignoring old cookies, and passing set cookies to redirects):
function uri_download($uri, $fileName) {
    // use cURL to download uri
    // make a curl resource, setting the uri as it's target to open
    $curl = curl_init($uri);
    // make a file resource and create/empty the file for writing
    $hFile = fopen($fileName, "w+");
    // set curl options
    // set the file resource that curl will write to
    curl_setopt($curl, CURLOPT_FILE, $hFile);
    // do not let curl output the HTTP headers
    curl_setopt($curl, CURLOPT_HEADER, false);
    // let curl follow redirects
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
    // set a location for curl to handle cookies
    curl_setopt($curl, CURLOPT_COOKIEJAR, "/tmp");
    // tell curl to mark this as a new cookie session
    curl_setopt($curl, CURLOPT_COOKIESESSION, true);
    // execute curl (download the uri to the temp file)
    // close the curl resource
    // unset the curl resource
    // close the temp file and file resource
    // unset the file resource

Chuck Renner wrote:
Quoted text here. Click to load it

Site Timeline