Page 1 of 1

file_get_contents problem

Posted: Tue Jul 25, 2006 2:10 am
by SomeOne
fist.. Hi to all!
I have a quiestion here...
1. what am i trying to do?
I want an PHP file execute and then get its source code (html) and then write this in a html file...
i tryed several things...though nothing wroked for me...
if i have a code like this..

Code: Select all

$content2 = file_get_contents('file.php');                                             

     $handlex = fopen('file.html', "w");                                            
   fwrite($handlex, $content2);                                                     
   fclose($handlex);
it works though....i get PHP source code in html file and not html source code....meaning that php file dose not execute...
can anyone help me please?
SomeOne :roll:

Posted: Tue Jul 25, 2006 2:13 am
by Benjamin

Code: Select all

$content2 = file_get_contents('http://www.domainname.com/file.php');

Posted: Tue Jul 25, 2006 2:14 am
by SomeOne
astions wrote:

Code: Select all

$content2 = file_get_contents('http://www.domainname.com/file.php');
dosent work...becouse i get an error: its disabled this function becouse of security risk :roll:

Posted: Tue Jul 25, 2006 2:17 am
by Benjamin
I'm not sure if there is an alternative way to do it, other than using eval() or something like that.
The PHP Manual wrote: allow_url_fopen boolean

This option enables the URL-aware fopen wrappers that enable accessing URL object like files. Default wrappers are provided for the access of remote files using the ftp or http protocol, some extensions like zlib may register additional wrappers.

Note: This setting can only be set in php.ini due to security reasons.

Note: This option was introduced immediately after the release of version 4.0.3. For versions up to and including 4.0.3 you can only disable this feature at compile time by using the configuration switch --disable-url-fopen-wrapper.
http://www.php.net/manual/en/ref.filesy ... -url-fopen

Posted: Tue Jul 25, 2006 2:21 am
by RobertGonzalez
SomeOne wrote:
astions wrote:

Code: Select all

$content2 = file_get_contents('http://www.domainname.com/file.php');
dosent work...becouse i get an error: its disabled this function becouse of security risk :roll:
That means that the server doesn't want you remoting into their system. Seems like a reasonable security precaution. Maybe you can contact that hosts administrator and see about getting permission to do what you want.

As an alternative, you can try cURL.

Posted: Tue Jul 25, 2006 3:20 am
by Ollie Saunders
In file.php:

Code: Select all

// put at the top, will catch all the output statements
ob_start()
// all your php code that generates file.html goes here
$buffer = ob_get_flush();
file_put_contents('file.html', $buffer); // save it in html