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
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
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
Share on other sites

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.