Jump to content

Beginner Help Please (includes)


chinrest

Recommended Posts

"Cut-n-paste" programmer here--go easy on me.

 

I've used this code before, but it does not work on my current host (Dreamhost):

 

<?php

$invalidChars=array("/",".","\\","\"",";");

$page=str_replace($invalidChars,"",$page);

include ("pages/".$page.".html");

?>

 

When I call index.php?page=home, I get this is the error message:

 

Warning: include(.html) [function.include]: failed to open stream: No such file or directory in /home/user/domain/dev/index.php on line 44

 

Warning: include() [function.include]: Failed opening '.html' for inclusion (include_path='.:/usr/local/php5/lib/php') in /home/user/domain/dev/index.php on line 44

 

 

If I replace the $page variable with an actual file, and call index.php in the browser, it works fine:

 

<?php

$invalidChars=array("/",".","\\","\"",";");

$page=str_replace($invalidChars,"",$page);

include ("pages/home.html");

?>

 

Any help?

Link to comment
https://forums.phpfreaks.com/topic/51846-beginner-help-please-includes/
Share on other sites

You have assumed that register_globals are enabled. While this used to be true many years ago, you can not and should not assume it anymore. Change your code to explicitly reference the appropriale superglobal array, in your case "$_GET".

 

<?php
$invalidChars=array("/",".","\\","\"",";");
$page=str_replace($invalidChars,"",$_GET['page']);
include ("pages/".$page.".html");
?>

 

Ken

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.