Jump to content

Dynamic URL PHP Include


presyce

Recommended Posts

I cant seem to get my index.php to include any pages. The include can only point to the default page. if it doesnt have a default page it points to 0.php and wont show other pages when the url is ...index.php?page=media

 

my code

<?php

$page = $_GET['page'];

$pages = array('home', 'news', 'media' '');

if (!empty($page)) {

if(in_array($page,$pages)) {

$page .= '.php';

include($page);

}

else {

echo 'Page not found. Return to

<a href="index.php">index</a>';

}

}

else {

include('home.php');

}

?>

 

my links

<a href="index.php?page=news">News</a>

 

THANKS A LOT!

Link to comment
https://forums.phpfreaks.com/topic/135456-dynamic-url-php-include/
Share on other sites

Could be because of a syntax error:

 

$pages = array('home', 'news', 'media', ''); // comma needed before the ''

 

But not sure why you would have '', it would allow for a .php included which would throw an error. I believe, but yea. See what that does for ya.

i just found the problem.. it was the code i had at the top of the page

<?php

$curdir = getcwd ();

chdir('/home/presyce/public_html/forum');

require_once('/home/presyce/public_html/forum/global.php');

chdir ($curdir);

?>

it was for my login code on my home page. the include works when i took this code off. why is this messing up my include though? thanks

i just found the problem.. it was the code i had at the top of the page

<?php

$curdir = getcwd ();

chdir('/home/presyce/public_html/forum');

require_once('/home/presyce/public_html/forum/global.php');

chdir ($curdir);

?>

it was for my login code on my home page. the include works when i took this code off. why is this messing up my include though? thanks

 

Do some debugging, echo out $curdir and see where it is sending you to. Are the files that you want to be included in that directory?

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.