Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

×
×
  • 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.