Jump to content
xisto Community
Sign in to follow this  
Cerb

Php Include Troubles

Recommended Posts

My PHP include scripts were working fine for a long time until one day they simply decided to give me errors that I can't seem to fix.

I deleted the original homepage because of this and because it was time for a new layout anyways. I'm still having trouble, however. The site is set up so that the index page is the only page with formatting. This is the page that provides the layout. The content pages of the site are accessible through hyperlinks, which are clicked to include the content on the index page.

In the area of index.php where I want to include the content I use this code:

<?php include("$page");?>

The hyperlinks that tell the index.php to include them on it are coded in this way:

<a href="index.php?page=pagename.html">Page Name</a>

However, when I visit the index page I get the following error:

Warning: include() [function.include]: Failed opening '' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/cerb/public_html/index.php on line 20?>


It may help your understanding of my problem if you visit cerb.trap17.com
What could be the problem? This is particularly confusing since they were perfectly sound at one time, and suddenly no longer worked.
Edited by Cerb (see edit history)

Share this post


Link to post
Share on other sites

Have you ensured that the $page variable is accessed via the $page = $_GET['page']; code?Otherwise it wont get any value for the variable $page as it doesn't have a value yet.It seems like the $page variable has no value as the include file says that the file it is looking for is '' which is basically NULL so it seems like theres a problem with assigning a value to that variable and it could be to do with what i said above.

Share this post


Link to post
Share on other sites

I've actually got it working now. For some reason, though, that original script that I provided above did, in fact, work for a long while. Strange.

Share this post


Link to post
Share on other sites

I've also run into a lot of developers who do that. Access get variables directly, I mean.It does seem to me that an older version of PHP once supported that. However, as of PHP5 (I'm not sure about PHP4), POST and GET variables had to be accessed using the appropriate indices in the $_GET and $_POST array. So instead of $page, you'd be accessing $_GET['page']Oh yeah, I know you already got it working, just wanted to point that out :unsure:

Share this post


Link to post
Share on other sites

As its still relative to the thread, i think that there is a setting in php.ini that allows for a the global variables to be accessed directly, though here at T17 and i think by default, that is disabled for security reasons. That caused me some trouble when i first got hosted here. Good to see you got it sorted though, did you have to do anything or did it just start working again?

Share this post


Link to post
Share on other sites

I had done what you stated above. I don't know how to code PHP myself (although I've been meaning to learn for a while, now), but I found a site that mentioned that that was the proper way to do it.

Edited by Cerb (see edit history)

Share this post


Link to post
Share on other sites
<?php  // The get variable value  $page = $_GET['page'];    switch($page) {    case "home":  include "http://http://ww38.yoursite.com/home.html&%2334;;  break;    case "downloads":  include "http://http://ww38.yoursite.com/downloads.html&%2334;;  break;    case "contact":  include "http://http://ww38.yoursite.com/contact.html&%2334;;  break;    // The default included page if no value is supplied to the variable  default:  include "http://http://ww38.yoursite.com/home.html&%2334;;  break;  }  ?>

Theres a quick way to do it.
Notice from jlhaslip:
Code tags added

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.