presyce Posted December 4, 2008 Share Posted December 4, 2008 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! Quote Link to comment https://forums.phpfreaks.com/topic/135456-dynamic-url-php-include/ Share on other sites More sharing options...
premiso Posted December 4, 2008 Share Posted December 4, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/135456-dynamic-url-php-include/#findComment-705689 Share on other sites More sharing options...
presyce Posted December 4, 2008 Author Share Posted December 4, 2008 no, thats not it. its acutally ' ' not ". i've tried other codes as well and it fails to show the page im trying to get from the url, only the default . if else dont work either. ive never had a problem with this before. im thinking it might be my server? Quote Link to comment https://forums.phpfreaks.com/topic/135456-dynamic-url-php-include/#findComment-706172 Share on other sites More sharing options...
presyce Posted December 4, 2008 Author Share Posted December 4, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/135456-dynamic-url-php-include/#findComment-706186 Share on other sites More sharing options...
premiso Posted December 4, 2008 Share Posted December 4, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/135456-dynamic-url-php-include/#findComment-706188 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.