Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.