Jump to content

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.

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?

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?

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.