Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Php Include Troubles
Cerb
post 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
Go to the top of the page
 
+Quote Post
shadowx
post 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.

Go to the top of the page
 
+Quote Post
Cerb
post 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.
Go to the top of the page
 
+Quote Post
salamangkero
post 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 happy.gif
Go to the top of the page
 
+Quote Post
shadowx
post 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?
Go to the top of the page
 
+Quote Post
Cerb
post 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
Go to the top of the page
 
+Quote Post
dwayne12
post 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.
Notice from jlhaslip:
Code tags added
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Php Include Root Ref(6)
  2. Girl Troubles(14)
  3. Include File.php?id=something(13)
  4. Include Funtion Php Problems(11)
  5. Please Help (g/f Troubles)(7)
  6. Include And Values(3)
  7. Where Is Include Path?!(5)
  8. Having Html Troubles......(0)
  9. Umart - Video Card Troubles(3)
  10. I Need Some Help(8)
  11. Possible Troubles With Gf(14)
  12. Topic View Changed To Include Custom Fields(3)
  13. Include() Statements(4)
  14. Forum Troubles(2)
  15. Source Code Troubles {delphi}(2)
  1. My Troubles With Linux(11)
  2. Text Image Java Problem(1)
  3. Php Include Problem [resolved](4)
  4. Harry Potter: The Deathly Hallows(18)
  5. Hosting Account Should Include Wysiwyg Editor(7)
  6. Does Php Include Work?(17)
  7. How Do I Include A Php Sidebar In My Website?(5)
  8. Question About Php Includes(17)
  9. Php - Forms, Date And Include(0)
  10. Logging In Troubles!(3)
  11. Lcd Troubles(4)
  12. Php Allow Url Include Question!(10)
  13. Panasonic Lumix - Problems With Movie Files(0)


 



-