Page 1 of 1

Problem with include

Posted: Mon Sep 06, 2004 11:38 am
by Getran
Hey ppl, i got a script that grabs a file and prints it. I made a post about displaying the contents of a file before, but i needed to use PHP in the files. Anyway, i changed the bit that opened it to just include(), but ran into a little problem. When it includes the page, it doesn't display it where i want it to... this is the script:

Code: Select all

if (isset($_REQUEST['page']))
{
  $inc = "pages/".$_REQUEST['page'].".php";
  if (!file_exists($inc))
  {
    $content = "Page not found";
  }
  else
  {
    $content = include($inc);
  }
}
else
{
    $content = include("pages/main.php");
}
It displays it at the top of the page, but i have another include in there to display navigation.php, which works fine..(in the correct place). Where i want that to display i just have echo $content;.

Also a weird thing i noticed, where the content should be displayed, it says "1" and nothing else.

Can someone help me with this ?

Thx in advance

Posted: Mon Sep 06, 2004 12:04 pm
by John Cartwright
echo include($page);

will return 1 if succesful 0 is not

if you want to contents of the page look into [php_man]file_get_contents[/php_man] ,[php_man]fopen[/php_man]

Posted: Mon Sep 06, 2004 3:12 pm
by Getran
nvm, i sorted it a different way

Posted: Mon Sep 06, 2004 3:19 pm
by John Cartwright
you should share your answers, so other ppl with the same problems can search :)

Posted: Mon Sep 06, 2004 6:28 pm
by timvw
always nice when people send stuff like

?page=../index etc ;)

Posted: Tue Sep 07, 2004 11:29 am
by Getran
oh sorry :roll:

I changed the bit i posted first to this:

Code: Select all

if (isset($_REQUEST['page']))
{
  $inc = "pages/".$_REQUEST['page'].".php";
  if (!file_exists($inc))
  {
    $content = "Page not found";
  }
  else
  {
    $method = "INCLUDEFILE";
    $content = "";
  }
}
else
{
    $method = "INCLUDEMAIN";
    $content = "";
}
Then changed echo $content; to:

Code: Select all

if ($method == "INCLUDEFILE")
{
  include($inc);
}
else if ($method == "INCLUDEMAIN")
{
  include("pages/main.php");
}
else
{
  echo $content;
}
Have fun lol