Help - Search - Members - Calendar
Full Version: Include
Zymic Webmaster Forums > Web Design & Development > Server Side Scripting > PHP
Scylince
I'm not quite sure if this is the appropriate forum for this question, but it is related none-the-less. I am currently building the frame work of my web site, as of now I am working on that navigation and I'm using a method which uses the include function.

The issue is that the function gives me an error about the include path. I'm trying to get it to access a folder within the root folder which is containing the file in which I wish to include.

It's a very popular, efficient method, I'm quite sure many of you use it, so that should be a plus for understanding my problem. Thanks in advance!
swordz
Please post the code you're using, and the exact php error you're getting. This will help us debug it!

swordz
Scylince
I'm not going into detail on how this works, but if you're attempting to help me, you should know, right?

CODE
<?php
if(empty($_GET["to"])) {
$_GET["to"] = "home";
}

include("include/" . $_GET["to"] . ".php");

?>


This isn't the code in full detail, such as leaving out html structure. Include is the name of the folder which is in the root folder, containing home.php.

root(folder) -> include(folder) -> home.php(file)

If you need further information, please be specific as I believe the above is sufficient enough.
Jetteh22
Please tell us exactly what error you're getting.
Copy and paste it for us in here.
Scylince
CODE
Warning: include(include/home.php) [function.include]: failed to open stream: No such file or directory in /www/uuuq.com/i/b/l/iblog/htdocs/index.php on line 30

Warning: include() [function.include]: Failed opening 'include/home.php' for inclusion (include_path='.:/usr/lib/php') in /www/uuuq.com/i/b/l/iblog/htdocs/index.php on line 30


I believe the error is related to the directory path, one problem being if I should start with a forward slash(/) or not. Then there is the problem of if I need to add another folder, in which I'm oblivious of, that would than lead to what I refer to as the local root folder (The one the contains the index file ex: index.php).
IamShipon1988
Can you show a quick structure of your site. I believe it is a wrong directory. Your code is correct.
Paradoks
may i suggest another different way of navigation? for future refrence look into turorials teaching you about the

<?php include ('header.php') ?>
the page

<?php include ('footer.php') ?>

as it will make coding alot easier in the long run i belive. I thank Andrew (trippin) for showing me this method ages ago.
shinjiketojapann
QUOTE(Paradoks @ Dec 30 2008, 07:19 AM) *
may i suggest another different way of navigation? for future refrence look into turorials teaching you about the

<?php include ('header.php') ?>
the page

<?php include ('footer.php') ?>

as it will make coding alot easier in the long run i belive. I thank Andrew (trippin) for showing me this method ages ago.
that was something i was doing from the beginning, when building frameworked websites with multiply files, it was annoying to edit each files header and footer when i made changes, what you said should be something EVERYONE should know how to do
Scylince
CODE
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>iBlog</title>
<link rel="stylesheet" type="text/css" href="css.css" />
<script type="text/javascript" src="js.js"></script>
</head>

<body id="home">
    <div id="page">
        <div id="head">
            <p id="time">&nbsp;</p>
            <ol id="index">
                <li><a href="#home">Home</a></li>
                <li><a href="#about">About</a></li>
                <li><a href="#portfolio">Portfolio</a></li>
                <li><a href="#blog">Blog</a></li>
                <li><a href="#article">Articles</a></li>
                <li><a href="#contact">Contact/Hire</a></li>
            </ol>
        </div>
        <div id="body">
            <p>Content</p>
        </div>
        <div id="foot">
            <ul>
                <li><a href="#">example</a></li>
                <li><a href="#">example</a></li>
                <li><a href="#">example</a></li>
            </ul>
        </div>
    </div>
</body>
</html>


The above is my current document structure. If you need the php code, look at the first post, if you need to know how I have my folder(s)/file(s) structured, look at the third post.

I'm not sure if you get the question Paradoks, I'm using that method, but using the GET method to receive data that contains the page in which I wish to retrieve and display within the div#body (<div id="body"><p>Content</p></div>).

I would really appreciate it if some one would solve this or direct me to a member of staff who may help me resolve this issue. It's stopping me from further designing/programming for my site, I'm using the site as a remote test server, even though I do have a local one installed which I haven't used in some time.
shinjiketojapann
try this code in place of your content,
it will make links as so

?act=page

CODE
<?php
if($_POST['do'] == "search" or $_GET['dosearch'] == "yes"){ $subaction = "search"; $dosearch = "yes"; include("./search.php"); }
elseif($_GET['act'] == "page1"){ include("./include/pageA.php"); }
elseif($_GET['act'] == "page2"){ include("./include/pageB.php"); }
else{ include("./include/default-page.php"); }
?>
(code is originally used in CuteNews, By CutePHP)

the code it self should be self explanatory,
the search is not needed for it to work.
Scylince
I'm not sure why no one really helped me with my issue, but I do appreciate the effort. I solved the problem by simply changing the directory folder name to "dir", instead of "include". For some odd reason, the include function does not accept a directory named after it.
Bogey
QUOTE(Scylince @ Jan 2 2009, 02:26 AM) *
I'm not sure why no one really helped me with my issue, but I do appreciate the effort. I solved the problem by simply changing the directory folder name to "dir", instead of "include". For some odd reason, the include function does not accept a directory named after it.

It always worked for me when my directory was named the same as the include function...
NDBoost
its because include is a reserved word...

Try using "Inc" instead of the full "Include" its like naming a folder if..
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2012 Invision Power Services, Inc.