JustinK101 Posted October 27, 2008 Share Posted October 27, 2008 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); Quote Link to comment https://forums.phpfreaks.com/topic/130316-how-to-use-fopen-on-a-dynamic-php-page/ Share on other sites More sharing options...
Maq Posted October 27, 2008 Share Posted October 27, 2008 Yes, that should work. The best way to find out is to test it out. Quote Link to comment https://forums.phpfreaks.com/topic/130316-how-to-use-fopen-on-a-dynamic-php-page/#findComment-675887 Share on other sites More sharing options...
JustinK101 Posted October 27, 2008 Author Share Posted October 27, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/130316-how-to-use-fopen-on-a-dynamic-php-page/#findComment-675889 Share on other sites More sharing options...
rhodesa Posted October 27, 2008 Share Posted October 27, 2008 is there a reason you aren't just including the page instead? EDIT: that is including the local file...like: include('order_form.php'); Quote Link to comment https://forums.phpfreaks.com/topic/130316-how-to-use-fopen-on-a-dynamic-php-page/#findComment-675900 Share on other sites More sharing options...
JustinK101 Posted October 27, 2008 Author Share Posted October 27, 2008 Because this is for an API that creates a PDF and does some other things, and they require pure output. Quote Link to comment https://forums.phpfreaks.com/topic/130316-how-to-use-fopen-on-a-dynamic-php-page/#findComment-675901 Share on other sites More sharing options...
PFMaBiSmAd Posted October 27, 2008 Share Posted October 27, 2008 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; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/130316-how-to-use-fopen-on-a-dynamic-php-page/#findComment-675927 Share on other sites More sharing options...
JustinK101 Posted October 28, 2008 Author Share Posted October 28, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/130316-how-to-use-fopen-on-a-dynamic-php-page/#findComment-676755 Share on other sites More sharing options...
JustinK101 Posted October 28, 2008 Author Share Posted October 28, 2008 OK, got it working, I was calling get_include_contents() from the same file I was passing into the function, so it keept on recalling itself. Quote Link to comment https://forums.phpfreaks.com/topic/130316-how-to-use-fopen-on-a-dynamic-php-page/#findComment-676779 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.