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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

Loading...
 Share

×
×
  • Create New...