|
|
|
|
![]() ![]() |
May 2 2007, 08:16 AM
Post
#1
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 241 Joined: 9-July 05 Member No.: 9,213 |
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: CODE <?php include("$page");?> The hyperlinks that tell the index.php to include them on it are coded in this way: CODE <a href="index.php?page=pagename.html">Page Name</a> However, when I visit the index page I get the following error: CODE 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. This post has been edited by Cerb: May 2 2007, 08:16 AM |
|
|
|
May 2 2007, 08:49 PM
Post
#2
|
|
|
A clever man learns from his own mistakes, a WISE man learns from those of OTHERS ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: [HOSTED] Posts: 976 Joined: 12-April 06 From: Essex, UK Member No.: 21,719 |
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. |
|
|
|
May 3 2007, 03:34 AM
Post
#3
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 241 Joined: 9-July 05 Member No.: 9,213 |
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.
|
|
|
|
May 3 2007, 03:43 PM
Post
#4
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: [HOSTED] Posts: 477 Joined: 15-August 06 From: Philippines Member No.: 28,387 |
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 |
|
|
|
May 3 2007, 04:49 PM
Post
#5
|
|
|
A clever man learns from his own mistakes, a WISE man learns from those of OTHERS ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: [HOSTED] Posts: 976 Joined: 12-April 06 From: Essex, UK Member No.: 21,719 |
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? |
|
|
|
May 4 2007, 12:50 AM
Post
#6
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 241 Joined: 9-July 05 Member No.: 9,213 |
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.
This post has been edited by Cerb: May 4 2007, 12:51 AM |
|
|
|
May 9 2007, 08:18 AM
Post
#7
|
|
|
Newbie [Level 2] ![]() ![]() Group: Members Posts: 25 Joined: 1-May 07 Member No.: 42,460 |
CODE <?php // The get variable value $page = $_GET['page']; switch($page) { case "home": include "http://www.yoursite.com/home.html"; break; case "downloads": include "http://www.yoursite.com/downloads.html"; break; case "contact": include "http://www.yoursite.com/contact.html"; break; // The default included page if no value is supplied to the variable default: include "http://www.yoursite.com/home.html"; break; } ?> Theres a quick way to do it. |
|
|
|
![]() ![]() |
Similar Topics
|