0

I added some php to some of my pages, but its not coming up on any of the pages.

<body class="menu">
    <!-- Slide bar starts here -->
   <?php require ('/Php/Slider.php');?>
    <!--Slide Bar Ends Here-->
    <div class="body">
        Store Comming Soon
    </div>
    <script src="store.js"></script>
</body>

in the php file I had this.

<header>
        <a href="#" class="menu-toggle">
            <div class="bar"></div>
            <div class="bar"></div>
            <div class="bar"></div>
        </a>
        <nav class="menu-side">
            <div class="listing">
                <div class="box"><a class="list" href="/"><h1>Home</h1></a></div>
                <div class="box"><a class="list" href="/DayZ_Home/"><h1>DayZ</h1></a></div>
                <div class="box"><a class="list" href="/Photos/"><h1>Photos</h1></a></div>
                <div class="box"><a class="list" href="/Store/"><h1>Store</h1></a></div>
            </div>
        </nav>
</header>

This is the exact same for all my pages, and nothing is coming up.

This is the error I get:

[02-Oct-2015 22:44:59 America/Denver] PHP Warning: include(): Failed opening '/Php/Slider.php' for inclusion (include_path='.:/usr/php/54/usr/lib64:/usr/php/54/usr/share/pear') in /home2/itskeega/public_html/index.php on line 14

Any Idea what is wrong?

3
  • 2
    check the path of file Slider.php is correct or not. Are you sure the file you're trying to include is in the include path Commented Oct 3, 2015 at 4:52
  • try this <?php require ('/Slider.php');?> Commented Oct 3, 2015 at 4:54
  • File paths in php run server side, in contrast to file paths (links) in html which runs in the clients browser. So while the link "/file" links to a file in your web root in html, "/file" in php will link to a file on the server root. I'd guess you mean to require('./Php/Slider.php') which tries to include Slider.php in the Php directory in the current directory. Commented Oct 3, 2015 at 5:37

4 Answers 4

1

Simply try this first : Remove slash in front of php in the path and run again. If that don't work continue reading.

Let me help you as much as I can.

First thing first, this

[02-Oct-2015 22:44:59 America/Denver] PHP Warning: include(): Failed
opening'/Php/Slider.php' for inclusion
(include_path='.:/usr/php/54/usr/lib64:/usr/php/54/usr/share/pear') in
/home2/itskeega/public_html/index.php on line 14

(just stating the obvious to me) This means,

  1. There is a FIle called 'index.php' in public_html directory
  2. It has a function "include()" on line 14 in its code.
  3. The include function have a path in parenthesis following it.
  4. There is a error in that path.
  5. Either file "Slider.php" is not there or the script can't read it.

how do i know it for sure ?

Failed opening'/Php/Slider.php' for inclusion

Why did I tell this ?

It will help to understand errors next time.

Now let's try to solve the error, what I would do first to confirm the file permissions and every other thing is

  1. Move the file to "public_html" folder itself.
  2. new Path will be just Slider.php (Take note of the case).
  3. Run your script and look for errors now.

That is the simplest way to do it.

Be very very precise in the "case" becuase I see you are not using the php conventions of naming everything.

Report back with the directory structure so we can help further.

Sign up to request clarification or add additional context in comments.

4 Comments

So Glad I could help. :)
my name in your comment is wrong , can you please correct it
well it worked for my home page but not any others, my homepage is /public_html/index.php but when i went to /public_html/Store/index.html it didnt work
see , you need to have your php file in the same page from where you are calling it. that way it will work. to make it work from all your pages you need to add relative path. for example , if you are in public_html link will be directly file name, if you are in another folder you have to come back to public_html using (../php/slider.php) <= try this link. when you are in a folder (store) and yes it depends on how deep in the directory you are
1

'/Php/Slider.php' I assume you have Slider.php inside Php directory, Now the correct way to include would be:

require ('../Php/Slider.php');

Which will go back first, open the Php directory folder and look for Slider.php file.

<body class="menu">
    <!-- Slide bar starts here -->
   <?php require ('../Php/Slider.php');?>
    <!--Slide Bar Ends Here-->
    <div class="body">
        Store Comming Soon
    </div>
    <script src="store.js"></script>
</body>

EDIT:

Moving forward from the comments under this answer, you stated your directory structure as:

/public_html/index.php (home page) 
/public_html/Php/Slider.php 

Which means the approach I stated was fine.

To go from index.php to Slider.php the way would be:

../ (Go back)
Php/ (Open the Php directory)
Slider.php (Look for Slider.php)

Hence, require ('../Php/Slider.php');

7 Comments

PHP Warning: include(): Failed opening '../Php/Slider.php' for inclusion (include_path='.:/usr/php/54/usr/lib64:/usr/php/54/usr/share/pear') in /home2/itskeega/public_html/index.php on line 14 I get this error
@KeeganO'Reilly Could you please provide your hierarchy of directories? I mean which file is present in which folder? The above answer with the approach to include would be fine to implement if you understand it and your own directories.
/public_html/index.php (home page) /public_html/Php/Slider.php Thoes are really all i think you need, the css and js are just files in the public_html
@KeeganO'Reilly I just read your title again Adding php to html. Are you by chance trying to include a .php extension file inside a .html extention file? If so, it won't work and you have to make the other one .php as well.
Well both files are php, I really didnt know how to word it, but i had a .html file and i added php so the file is now .php
|
0

As you mentioned that you are including this file in whole project , yet you did not mention the dirctory structure . It is always better to include files with absolute path . try as below -

<body class="menu">
    <!-- Slide bar starts here -->
   <?php
     $file=$_SERVER['DOCUMENT_ROOT']."<--your project dir-->".'/Php/Slider.php';
    require ($file);
    ?>
    <!--Slide Bar Ends Here-->
    <div class="body">
        Store Comming Soon
    </div>
    <script src="store.js"></script>
</body>

Comments

0
<?php require ($_SERVER["DOCUMENT_ROOT"]."/path/to/file.php");?>

$_SERVER["DOCUMENT_ROOT"]. Makes your path start at /public_html/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.