8 Replies - 1261 Views - Last Post: 14 March 2014 - 10:35 AM

#1 agent46  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 46
  • Joined: 10-January 14

Help? Error msgs when including header.php in index.php file

Posted 13 March 2014 - 01:57 PM

Hello Dream in Coders,

I'm looking for some help on this PHP problem. This is the first time I've attempted to use PHP, so I'm pretty much feeling my way in dark here so far - using tutorials etc.

Here's the Situation:
  • I'm developing and testing a website on a local XAMPP server.
  • My "homepage" is index.php, located in the root directory.
  • I have coded a header with a working spry navigation menu and placed it in a file called header.php, located in ../_php.
  • I've placed a PHP "include" statement on line 50 in the index.php file.


Quote

<?php include("../_php/header.php"); ?>


Here's the Problem
The server sends me two error messages:

Quote

Warning: include(../_php/header.php): failed to open stream: No such file or directory in C:\XAMPP\htdocs\rothwebsite\index.php on line 50

Warning: include(): Failed opening '../_php/header.php' for inclusion (include_path='.;C:\XAMPP\php\PEAR') in C:\XAMPP\htdocs\rothwebsite\index.php on line 50


I suspect there's a problem with my relative paths, but I don't understand the warnings. I'd appreciate if some experienced people here can review my code and maybe help me locate the source and meaning of my errors.

Here's the Code:
<!-- this is code from index.php -->

<!doctype html>
<!--  Designed & Produced by Tam Velazquez-Duong Jr., index.php v1.0 Release: 2014XXXX --> 
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Put yr homepage info here. Should be a couple long sentences"/>
<meta name="keywords" content="keyword keyphrase etc"/>
<meta name="rating" content="general"/>
<meta name="revisit-after" content="14 days"/>
<meta name="ROBOTS" content="All"/>
<title>Roth Metal Flake Homepage</title>
<link rel="icon" href="_image/favicon.ico" type="image/x-icon"/>
<link href="_css/boilerplate.css" rel="stylesheet" type="text/css">
<link href="_css/main.css" rel="stylesheet" type="text/css">
</head>
<body>
<div class="gridContainer clearfix">
<?php include("../_php/header.php"); ?>
</div>
</body>
</html>  

<!-- this is code from header.php -->

<!doctype html>
<!--  Designed & Produced by Tam Velazquez-Duong Jr., index.php v1.0 Release: 2014XXXX --> 
<!--[if lt IE 7]> <html class="ie6 oldie"> <![endif]-->
<!--[if IE 7]>    <html class="ie7 oldie"> <![endif]-->
<!--[if IE 8]>    <html class="ie8 oldie"> <![endif]-->
<!--[if gt IE 8]><!-->
<html class="">
<!--<![endif]-->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Put yr homepage info here. Should be a couple long sentences"/>
<meta name="keywords" content="keyword keyphrase etc"/>
<meta name="rating" content="general"/>
<meta name="revisit-after" content="14 days"/>
<meta name="ROBOTS" content="All"/>
<title>Roth Metal Flake Homepage</title>
<link rel="icon" href="../_image/favicon.ico" type="image/x-icon"/>
<link href="../_css/boilerplate.css" rel="stylesheet" type="text/css">
<link href="../_css/main.css" rel="stylesheet" type="text/css">
<link href="../_spry_assets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css">
<link href="../jQuery/css/style.css" rel="stylesheet" type="text/css">
<script src="../_spry_assets/SpryMenuBar.js" type="text/javascript"></script>

<!-- 
To learn more about the conditional comments around the html tags at the top of the file:
paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/

Do the following if you're using your customized build of modernizr (http://www.modernizr.com/):
* insert the link to your js here
* remove the link below to the html5shiv
* add the "no-js" class to the html tags at the top
* you can also remove the link to respond.min.js if you included the MQ Polyfill in your modernizr build 
-->
<!--[if lt IE 9]>
<link rel="stylesheet" type="text/css" href="includes/menu_ie7_and_ie8.css" />
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>

<body>
  <header>
  <a href="../index.php" tabindex="1" title="Back to Home" target="_top">
    	<img id="logo" src="../_image/_navBar/rmfLogo.png"></a>
        
<ul id="navBar" class="MenuBarHorizontal">
      <li><a class="MenuBarItemSubmenu" href="#">PRODUCTS</a>
            <ul>
                  <li><a class="MenuBarItemSubmenu" href="../_page/metalflake_launch.php">Metal Flake </a>
                        <ul>
                              <li><a class="MenuBarItemSubmenu3"  href="../_page/metalflake_solid.php">Solids</a></li>
                              <li><a class="MenuBarItemSubmenu3" href="../_page/metalflake_trippin.php">Trippin'</a></li>
                        </ul>
                  </li>
                  <li><a class="MenuBarItemSubmenu" href="../_page/rattlebomb_launch.php">Rattle Bombs</a>
                        <ul>
                              <li><a class="MenuBarItemSubmenu3" href="../_page/rattlebomb_flake.php">Flakes</a></li>
                              <li><a class="MenuBarItemSubmenu3" href="../_page/rattlebomb_base.php">Bases</a></li>
                              <li><a class="MenuBarItemSubmenu3" href="../_page/rattlebomb_kandy.php">Kandies</a></li>
                              <li><a class="MenuBarItemSubmenu3" href="../_page/rattlebomb_pearl.php">Pearls</a></li>
                              <li><a class="MenuBarItemSubmenu3" href="../_page/rattlebomb_pearl.php">All-In-One</a></li>
                        </ul>
                  </li>
                  <li><a class="MenuBarItemSubmenu" href="../_page/pearlfactory_launch.php">Pearl Factory</a>
                        <ul>
                        <li><a class="MenuBarItemSubmenu3" href="../_page/pearlfactory_standard.php">Standard</a></li>
                        <li><a class="MenuBarItemSubmenu3" href="../_page/pearlfactory_skitzo.php">Skitzo</a></li>
                        <li><a class="MenuBarItemSubmenu3" href="../_page/pearlfactory_diamond.php">Diamond</a></li>
                        </ul>
                  </li>
                  <li><a class="MenuBarItemSubmenu2" href="../_page/pinstriping.php">Pinstriping</a></li>
                  <li><a class="MenuBarItemSubmenu2" href="../_page/sprayguns.php">Spray Guns</a></li>
                  <li><a class="MenuBarItemSubmenu2" href="../_page/chipcharts.php">Chip Charts</a></li>
                  <li><a class="MenuBarItemSubmenu2" href="../_page/exxxtras.php">Exxxtras</a></li>
                  <li><a class="MenuBarItemSubmenu2" href="../_page/techsheets.php">Tech Sheets</a></li>
            </ul>
      </li>
      <li><a href="../_page/rothacademy.php">ROTH ACADEMY</a></li>
      <li><a href="../_page/distributors.php">DISTRIBUTORS</a></li>
      <li><a href="../_page/gallery.php">GALLERY</a></li>
      <li><a href="../_page/contact.php">ABOUT US</a></li>   
</ul>  </header>

</div>
<script type="text/javascript">
var MenuBar1 = new Spry.Widget.MenuBar("navBar", {imgDown:"_spry_assets/SpryMenuBarDownHover.gif", imgRight:"_spry_assets/SpryMenuBarRightHover.gif"});
</script>
</body>
</html>



Please don't get to caught up in the code for the nav menu. It works. The main question here is why am I getting these two Warning messages from the XAMPP server.

Many Thanks in Advance,
Mick

This post has been edited by agent46: 13 March 2014 - 01:59 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Help? Error msgs when including header.php in index.php file

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13656
  • View blog
  • Posts: 54,497
  • Joined: 12-June 08

Re: Help? Error msgs when including header.php in index.php file

Posted 13 March 2014 - 02:01 PM

.. any particular reason you have a file called _php in your project's root folder?
Was This Post Helpful? 0
  • +
  • -

#3 agent46  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 46
  • Joined: 10-January 14

Re: Help? Error msgs when including header.php in index.php file

Posted 13 March 2014 - 02:11 PM

Hi Modi123_1,

_php is a file folder in the root directory. I use file folders to locate pages, scripts and images discretely by category. All my file directory names begin with "_".

Thanks,
Mick

This post has been edited by agent46: 13 March 2014 - 02:19 PM

Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13656
  • View blog
  • Posts: 54,497
  • Joined: 12-June 08

Re: Help? Error msgs when including header.php in index.php file

Posted 13 March 2014 - 02:17 PM

... and have you just tried:
<?php include("/_php/header.php"); ?>


?
Was This Post Helpful? 1
  • +
  • -

#5 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 4139
  • View blog
  • Posts: 13,089
  • Joined: 08-June 10

Re: Help? Error msgs when including header.php in index.php file

Posted 13 March 2014 - 02:20 PM

Quote

I suspect there's a problem with my relative paths, but I don't understand the warnings.

it simply means there is no file C:\XAMPP\htdocs\_php\header.php or C:\XAMPP\php\_php\header.php
Was This Post Helpful? 1
  • +
  • -

#6 agent46  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 46
  • Joined: 10-January 14

Re: Help? Error msgs when including header.php in index.php file

Posted 13 March 2014 - 02:26 PM

The path syntax "../_foldername/filename.ext" works everywhere else on the site, so no I haven't. What's the difference between my syntax and yours? I'm curious.


Ah! yes, of course. You're right. The index.php is in the root directory so it needs a different path.

Thanks,
Mick

This post has been edited by agent46: 13 March 2014 - 02:30 PM

Was This Post Helpful? 0
  • +
  • -

#7 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 4139
  • View blog
  • Posts: 13,089
  • Joined: 08-June 10

Re: Help? Error msgs when including header.php in index.php file

Posted 13 March 2014 - 02:29 PM

maybe you have an invisible char somewhere in the path?
Was This Post Helpful? 0
  • +
  • -

#8 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13656
  • View blog
  • Posts: 54,497
  • Joined: 12-June 08

Re: Help? Error msgs when including header.php in index.php file

Posted 13 March 2014 - 02:31 PM

../ can be interpreted as 'pop to a the parent directory and go look' versus stay here and look.
Was This Post Helpful? 1
  • +
  • -

#9 agent46  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 46
  • Joined: 10-January 14

Re: Help? Error msgs when including header.php in index.php file

Posted 14 March 2014 - 10:35 AM

Thanks for the help everyone.

Here's the revised situation:
I built the header with the NavBar into my original index.php page. Now I understand using an include statement for a separate header.php page would be a better design strategy. It reduces overhead and allows me to edit the NavBar once on a single page instead of every page on the site, should any changes be needed.

So basically, now I'm trying to perform surgery here.

I need to:
  • Determine what, if any, code needs to remain on the index.php page.
  • Determine what code needs to be transplanted to the header.php page.
  • Extract all the necessary Spry NavBar code from the index.php page and transfer it to the header.php page.
  • Make any adjustments to the transferred code as needed.


I'm also using a social media widget on the index page which uses JQuery scripting so I have to leave any of that code in the <head> section intact.

The index page <head> section looks like this now:

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Put homepage info here. Should be a couple long sentences"/>
<meta name="keywords" content="keyword keyphrase etc"/>
<meta name="rating" content="general"/>
<meta name="revisit-after" content="14 days"/>
<meta name="ROBOTS" content="All"/>

<title>Roth Metal Flake Homepage</title>

<link rel="icon" href="_image/favicon.ico" type="image/x-icon"/>
<link href="_css/boilerplate.css" rel="stylesheet" type="text/css">
<link href="_css/main.css" rel="stylesheet" type="text/css">
<link href="_spry_assets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css">
<link href="jQuery/css/style.css" rel="stylesheet" type="text/css">
<script src="_spry_assets/SpryMenuBar.js" type="text/javascript"></script>
<script src="jQuery/js/jquery-1.4.2.js" type="text/javascript"></script> 
<script src="jQuery/js/jquery.jsocial.js" type="text/javascript"></script>

<!--[if lt IE 9]>
<link rel="stylesheet" type="text/css" href="includes/menu_ie7_and_ie8.css" />
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->

<script type="text/xml">

<!--
<oa:widgets>
  <oa:widget wid="2149023" binding="#social" />
</oa:widgets>
-->
</script>
</head>



Here is the header NavBar related code from the <body> section of the index page:

  <header>
  <a href="index.php" tabindex="1" title="Back to Home" target="_top">
    	<img id="logo" src="_image/_navBar/rmfLogo.png"></a>
        
<ul id="navBar" class="MenuBarHorizontal">
      <li><a class="MenuBarItemSubmenu" href="#">PRODUCTS</a>
            <ul>
                  <li><a class="MenuBarItemSubmenu" href="_page/metalflake_launch.php">Metal Flake </a>
                        <ul>
                              <li><a class="MenuBarItemSubmenu3"  href="_page/metalflake_solid.php">Solids</a></li>
                              <li><a class="MenuBarItemSubmenu3" href="_page/metalflake_trippin.php">Trippin'</a></li>
                        </ul>
                  </li>
                  <li><a class="MenuBarItemSubmenu" href="_page/rattlebomb_launch.php">Rattle Bombs</a>
                        <ul>
                              <li><a class="MenuBarItemSubmenu3" href="_page/rattlebomb_flake.php">Flakes</a></li>
                              <li><a class="MenuBarItemSubmenu3" href="_page/rattlebomb_base.php">Bases</a></li>
                              <li><a class="MenuBarItemSubmenu3" href="_page/rattlebomb_kandy.php">Kandies</a></li>
                              <li><a class="MenuBarItemSubmenu3" href="_page/rattlebomb_pearl.php">Pearls</a></li>
                              <li><a class="MenuBarItemSubmenu3" href="_page/rattlebomb_pearl.php">All-In-One</a></li>
                        </ul>
                  </li>
                  <li><a class="MenuBarItemSubmenu" href="_page/pearlfactory_launch.php">Pearl Factory</a>
                        <ul>
                        <li><a class="MenuBarItemSubmenu3" href="_page/pearlfactory_standard.php">Standard</a></li>
                        <li><a class="MenuBarItemSubmenu3" href="_page/pearlfactory_skitzo.php">Skitzo</a></li>
                        <li><a class="MenuBarItemSubmenu3" href="_page/pearlfactory_diamond.php">Diamond</a></li>
                        </ul>
                  </li>
                  <li><a class="MenuBarItemSubmenu2" href="_page/pinstriping.php">Pinstriping</a></li>
                  <li><a class="MenuBarItemSubmenu2" href="_page/sprayguns.php">Spray Guns</a></li>
                  <li><a class="MenuBarItemSubmenu2" href="_page/chipcharts.php">Chip Charts</a></li>
                  <li><a class="MenuBarItemSubmenu2" href="_page/exxxtras.php">Exxxtras</a></li>
                  <li><a class="MenuBarItemSubmenu2" href="_page/techsheets.php">Tech Sheets</a></li>
            </ul>
      </li>
      <li><a href="_page/rothacademy.php">ROTH ACADEMY</a></li>
      <li><a href="_page/distributors.php">DISTRIBUTORS</a></li>
      <li><a href="_page/gallery.php">GALLERY</a></li>
      <li><a href="_page/contact.php">ABOUT US</a></li>   
</ul>  </header>

<script type="text/javascript">
var MenuBar1 = new Spry.Widget.MenuBar("navBar", {imgDown:"_spry_assets/SpryMenuBarDownHover.gif", imgRight:"_spry_assets/SpryMenuBarRightHover.gif"});
</script>
</body>



Could we have a discussion about this surgery and how to get it done? I appreciate everyone's input. I hope I can get skilled enough working on this to help other folks later on.

Thanks in Advance,
Mick
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1