Jump to content

Include


alen

Recommended Posts

This is my include script:

 

<?PHP                   
$incpath = "include";
$default = "index"; 
$getarray = "side"; 
$filendelse = "php";

if (isset($_GET[$getarray]))
{
    include_once ("$incpath/".$_GET[$getarray].".$filendelse");
}
else
{
    include_once ("$incpath/$default.$filendelse");
}        
?> 

 

It works like this, I have a index.php file in the include folder and a index.php file in the public_html folder. When I enter localhost I get the content of index.php in the include folder since index.php in the public_html folder includes the index file in the include folder. And I have some other links in the include folder too, and I can easily change to another link with http://localhost/index.php?id=name - But let's say I don't have a file named hello.php in the include folder. How can I make the script automatically open a file called 404.php then?

 

Best regards

Your friendly neighbour Alen!

Link to comment
https://forums.phpfreaks.com/topic/38498-include/
Share on other sites

What about this,

 

<?php
error_reporting(0);
$filnavn = $_GET['var'];
$filendelse = '.php';
if (!$filnavn) {
$filnavn = 'default';
}
if (!eregi("^((.*)/)", $filnavn))  {
  include $filnavn . $filendelse;
}
else {
  include "404.php";
}
?>

 

It works fine, but when I go to index.php?var=unknownpage I doesn't include 404.php.

 

How can I use file_exists() here? I use if (!eregi("^((.*)/)", $filnavn)) so people can't access other folders.

Link to comment
https://forums.phpfreaks.com/topic/38498-include/#findComment-184868
Share on other sites

<?php
error_reporting(0);
$filnavn = $_GET['var'];
$filendelse = '.php';
if (!$filnavn) { 
$filnavn = 'default'; 
}
$filnavn = 'include';

if (file_exists($filnavn)) {
include $filnavn . $filendelse;
} else {
include "404.php";
}
if (!eregi("^((.*)/)", $filnavn)) {
  include $filnavn . $filendelse;
}
else {
  include "404.php";
}
?>

 

This must be wrong. Couldn't you just help me out a little. Give me a jumpstart?

Link to comment
https://forums.phpfreaks.com/topic/38498-include/#findComment-184879
Share on other sites

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.