SitePoint Sponsor

User Tag List

Results 1 to 23 of 23
  1. #1
    SitePoint Addict hurricanedan's Avatar
    Join Date
    Feb 2006
    Location
    North Carolina
    Posts
    288
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Getting a require_once() error (and others)

    I am attempting to troubleshoot a site for someone that was designed by someone else and the pages are not displaying. The original designer can't be reach unfortunately. There are a couple of issues but this is the first:

    I get the following error if I go to a page directly (example.com/pages/home.php)

    Fatal error: require_once() [function.require]: Failed opening required 'header.php' (include_path='.;C:\php\pear\;') in C:\Webspace\www\site\pages\home.php on line 8

    If I go to example.com/index.php I can get to the /pages/home.php page. Here is the relevant code from index.php:

    PHP Code:
    <?php
     
    require_once("functions.php");

     
    session_start();
     if(!isset(
    $_REQUEST["action"])){
      
    //default page to show if there is no action request variable
      
    require_once("pages/home.php");
      die();
     }

     if(
    $_REQUEST["action"] == "site"){
      
    //show list of sites - "browse birds by site"
      
    require_once("pages/site.php");
      die();
     }


     
    //if we for some reason fall through all of the actions, take a safe default action of requesting the home page
     
    require_once("pages/home.php");

    ?>
    And here is the /pages/home.php
    PHP Code:
    <?php
    // home.php
    // The "front page" of the site

     
    session_start();

    // Output page header
     
    require_once("header.php");
    ?>
      <div><a href="./?action=site">Browse birds by site</a></div>
      <div><a href="./?action=bird">Browse sites by bird</a></div>
    <?php

    // Output page footer
     
    require_once("footer.php");
    ?>
    Thanks,

    Dan

  2. #2
    Use The Cloud
    Join Date
    Jan 2006
    Location
    Boise, ID
    Posts
    556
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by hurricanedan View Post
    If I go to example.com/index.php I can get to the /pages/home.php page. Here is the relevant code:
    Can you clarify this? When you go through index.php, what exactly is shown in your address bar when you're looking at home.php?
    Brad Hanson, Web Applications & Scalability Specialist
    ► Is your website outgrowing its current hosting solution?
    ► PM me for a FREE scalability consult!
    ► USA Based: Available by Phone, Skype, AIM, and E-mail.

  3. #3
    SitePoint Addict hurricanedan's Avatar
    Join Date
    Feb 2006
    Location
    North Carolina
    Posts
    288
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sure - When I go through index.php the contents of home.php are displayed. This includes the two links and the footer content (some text) but the address bar still displays http://example.com/index.php

    Does that clear anything up?

  4. #4
    Use The Cloud
    Join Date
    Jan 2006
    Location
    Boise, ID
    Posts
    556
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It looks like he set up a primitive front controller. Which means, accessing the pages directly will not work as they are designed to be included into the index page.

    What is wrong with viewing home.php through index.php?

    Edit:

    Which means, it looks like the site was designed to be accessed like this: index.php?action=PAGE
    Brad Hanson, Web Applications & Scalability Specialist
    ► Is your website outgrowing its current hosting solution?
    ► PM me for a FREE scalability consult!
    ► USA Based: Available by Phone, Skype, AIM, and E-mail.

  5. #5
    SitePoint Addict hurricanedan's Avatar
    Join Date
    Feb 2006
    Location
    North Carolina
    Posts
    288
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You are right about how the site is to be accessed. Here is the site: http://www.ncbirdingtrail.org/ncbirdingsite/index.php

    but here is the kicker, click on either of those links and it does try to do the action=???? but fails. I was just trying to see what would happen if you went to the pages directly and was getting this error.

    Sorry to change the subject of the thread but can you tell me why the controller might not be working?

    If it makes a difference, the site was designed on a unix/linux server and is now being hosted on a windows server (that is where I think the problem is, but at this point I am guessing).

    Thanks again.

  6. #6
    Use The Cloud
    Join Date
    Jan 2006
    Location
    Boise, ID
    Posts
    556
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The problem has nothing to do with PHP, it's a web server configuration issue.

    http://www.ncbirdingtrail.org/ncbird...hp?action=site - works

    but http://www.ncbirdingtrail.org/ncbird...e/?action=site does not.

    So your webserver is thinking the latter is trying to read the directory instead of routing it through the index page.

    I don't know anything about Windows so someone else will have to chime in on how to fix it with (presumably) IIS.
    Brad Hanson, Web Applications & Scalability Specialist
    ► Is your website outgrowing its current hosting solution?
    ► PM me for a FREE scalability consult!
    ► USA Based: Available by Phone, Skype, AIM, and E-mail.

  7. #7
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    If your using Apache, add index.php to your DirectoryIndex list. I'm pretty sure IIS has something similar.

    BTW, great investigatory skills Brad.

    Edit: Indeed it does, linkie.
    Last edited by AnthonySterling; Jan 23, 2009 at 15:36. Reason: IIS Link
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  8. #8
    SitePoint Enthusiast
    Join Date
    Nov 2008
    Location
    New York
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To answer you original question. It is not working when accessed directly because header.php is local to index.php not to page.php meaning that it is located in <<example.com>> folder not in <<example.com/pages>> folder.

    As far as second question goes clicking on either link is calling index.php with 'action' parameter set to 'site' or 'bird' and I do not see any code in index.php to act upon this param so either there is some code to handle them in functions.php (unlikely) or you are not posting full index.php code.
    www.forkaya.com - Web Development, PHP Scripting

  9. #9
    SitePoint Addict hurricanedan's Avatar
    Join Date
    Feb 2006
    Location
    North Carolina
    Posts
    288
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Brad - I have to say, Thanks. That is what is happening, the index.php is not being handled.

    I think I will work this over to the server config forum but if anyone has an answer please let me know.

    Thanks,

    Dan

  10. #10
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    if anyone has an answer please let me know
    See my previous post, and attempt to steal Brad's thunder.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  11. #11
    SitePoint Enthusiast
    Join Date
    Nov 2008
    Location
    New York
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by bhanson View Post
    The problem has nothing to do with PHP, it's a web server configuration issue.

    http://www.ncbirdingtrail.org/ncbird...hp?action=site - works

    but http://www.ncbirdingtrail.org/ncbird...e/?action=site does not.

    So your webserver is thinking the latter is trying to read the directory instead of routing it through the index page.

    I don't know anything about Windows so someone else will have to chime in on how to fix it with (presumably) IIS.
    so why not modify the code to look like this:
    PHP Code:
      <div><a href="./index.php?action=site">Browse birds by site</a></div>
      <
    div><a href="./index.php?action=bird">Browse sites by bird</a></div
    www.forkaya.com - Web Development, PHP Scripting

  12. #12
    SitePoint Addict hurricanedan's Avatar
    Join Date
    Feb 2006
    Location
    North Carolina
    Posts
    288
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    SilverB - I did not see the edit originally. Thanks for the link.

    Let me give this a try.

    Dan

  13. #13
    SitePoint Addict hurricanedan's Avatar
    Join Date
    Feb 2006
    Location
    North Carolina
    Posts
    288
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Forkaya - that may be what I will need to do. I am trying SilverB's suggestion and going from there.

    Thanks,

    Dan

  14. #14
    Use The Cloud
    Join Date
    Jan 2006
    Location
    Boise, ID
    Posts
    556
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by forkaya View Post
    so why not modify the code to look like this:
    That will work, but it makes the links even uglier!

    The best solution is to probably use some sort of rewrite rule to transform /PAGENAME to index.php?action=PAGENAME.
    Brad Hanson, Web Applications & Scalability Specialist
    ► Is your website outgrowing its current hosting solution?
    ► PM me for a FREE scalability consult!
    ► USA Based: Available by Phone, Skype, AIM, and E-mail.

  15. #15
    SitePoint Addict hurricanedan's Avatar
    Join Date
    Feb 2006
    Location
    North Carolina
    Posts
    288
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I know how to use mod_rewrite (to an extent) but I can't do that on a Windows box can I?

  16. #16
    SitePoint Enthusiast
    Join Date
    Nov 2008
    Location
    New York
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Depends what web server are you using?
    www.forkaya.com - Web Development, PHP Scripting

  17. #17
    Use The Cloud
    Join Date
    Jan 2006
    Location
    Boise, ID
    Posts
    556
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by hurricanedan View Post
    I know how to use mod_rewrite (to an extent) but I can't do that on a Windows box can I?
    Well, yes, but in your situation the best answer I can give is "maybe."

    Usually people don't run Windows boxes to run Apache/PHP, but some people do. If your box is using Apache then the configuration should be nearly identical to that on a linux machine.

    If your box is using IIS, mod_rewrite won't work, but I'm sure it has some sort of equivalent. (And I think there may be a mod_rewrite plugin).
    Brad Hanson, Web Applications & Scalability Specialist
    ► Is your website outgrowing its current hosting solution?
    ► PM me for a FREE scalability consult!
    ► USA Based: Available by Phone, Skype, AIM, and E-mail.

  18. #18
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by hurricanedan View Post
    I know how to use mod_rewrite (to an extent) but I can't do that on a Windows box can I?
    There are plenty of paid solutions out there, but as far as I'm aware there are no in-built IIS alternatives.

    I think modifying your default index documents is going to be your cheapest and easiest solution.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  19. #19
    SitePoint Enthusiast
    Join Date
    Nov 2008
    Location
    New York
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am running Apache/PHP under Windows XP Professional on one of my boxes but have not had too much success with mod_rewrite on it
    www.forkaya.com - Web Development, PHP Scripting

  20. #20
    SitePoint Addict hurricanedan's Avatar
    Join Date
    Feb 2006
    Location
    North Carolina
    Posts
    288
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It is an IIS install, no apache. I have taken a quick look and it would only require a find/replace on 24 lines of code. So I think that will be the way I need to go about it.

    Thanks for everyone's help,

    Dan

  21. #21
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Is there a reason you're not altering the default index documents? It is by far, the more appropriate solution...
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  22. #22
    SitePoint Addict hurricanedan's Avatar
    Join Date
    Feb 2006
    Location
    North Carolina
    Posts
    288
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am not changing the default index document because the server is also a .asp server and I am a little nervous about adding the index.php item to the list.

    I have asked the person who asked me for help if we can do this but I am still waiting to hear back from him.

    The way I understand it a browser would attempt to load whatever the items in the default list are, from top to bottom; is that correct?

  23. #23
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Indeed.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •