file_get_contents problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
SomeOne
Forum Commoner
Posts: 27
Joined: Tue Jul 25, 2006 2:06 am

file_get_contents problem

Post 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:
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Code: Select all

$content2 = file_get_contents('http://www.domainname.com/file.php');
User avatar
SomeOne
Forum Commoner
Posts: 27
Joined: Tue Jul 25, 2006 2:06 am

Post 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:
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post 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
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post 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
Post Reply