Jump to content

How To Use FOPEN On A Dynamic PHP Page


JustinK101

Recommended Posts

I am trying to use fopen() and then fread() to get the contents of a dynamically generated PHP page. Basically I have a page `order_form.php` which has fields that arre dynamically generated from a SESSION.

 

Is it possible to do something like:

 

$handle = fopen("http://www.mydomain.com/order_form.php", "rb");
$contents = stream_get_contents($handle);
fclose($handle);

Link to comment
https://forums.phpfreaks.com/topic/130316-how-to-use-fopen-on-a-dynamic-php-page/
Share on other sites

Ok, problem. The output is claiming that the session does'nt exist. Which probably makes sense because it doesn't know about the session. Anyway around this? Can I pass a session into stream_get_contents() or something like that?

You can use output buffering to get the content generated by an include -

 

<?php
$string = get_include_contents('somefile.php');

function get_include_contents($filename) {
    if (is_file($filename)) {
        ob_start();
        include $filename;
        $contents = ob_get_contents();
        ob_end_clean();
        return $contents;
    }
    return false;
}

?> 

PFMaBiSmAd,

 

When I use this, I got the following error:

 

PHP has encountered a Stack overflow

 

I had to put the function (get_include_contents) in a seperate file (functions.php) and require_once("functions.php") to get around it wanking about function already defined.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.