Jump to content

php - cannot pass argument [solved]


Recommended Posts

I am attempting to get to know php but cannot get the simplest of pages to work.

 

I have installed apache 2.0.54 and php 5.0.4

 

I have copied a script:

<?php
if (!isset($page)) $page = 'default.html';

$page = "$page";
$fp = fopen($page,"r");
$content = fread($fp, filesize($page));
fclose($fp);

$content = str_replace('[HEADER]','<?php include\'header.php\';?>', $content);
$content = str_replace('[FOOTER]','<?php include\'footer.php\';?>', $content);
$content = str_replace('[NEWSLETTERSIGNUP]','<?php include\'nlsignup.php\';?>', $content);
eval('?>'.$content);
?>

and the relevant html files as well as an html file called welcome.html:

[HEADER]

Welcome to some text

[NEWSLETTERSIGNUP]

[FOOTER]

When I attempt to display the file however using

http://localhost/default.php?page=welcome.html

in firefox, nothing is displayed.

 

My apache log shows the following errors:

[client 127.0.0.1] PHP Warning:  fopen(default.html) [<a href='function.fopen'>function.fopen</a>]: failed to open stream: No such file or directory in /var/www/html/default.php on line 6
[client 127.0.0.1] PHP Warning:  filesize() [<a href='function.filesize'>function.filesize</a>]: stat failed for default.html in /var/www/html/default.php on line 7
[client 127.0.0.1] PHP Warning:  fread(): supplied argument is not a valid stream resource in /var/www/html/default.php on line 7
[client 127.0.0.1] PHP Warning:  fclose(): supplied argument is not a valid stream resource in /var/www/html/default.php on line 8

all the files are saved under /var/www/html.

If I amend the code to set $page to the welcome.html file then it all works, but it will not allow me to pass in the file as an argument.

 

I hae a suspicion that it is my setup that is wrong but do not know where to start.

 

Any help would be grtatefully received.

 

thanks

Leo

Edited by Leo
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...