Jump to content

help on includes(not linking corrrectly)


L

Recommended Posts

Hey,

sorry if this has been asked before but i couldn't find it in the search...

but anyway my problem is that my a.php page is in a folder called main in the root...so the url would be http://www.mysite.com/main/a.php

But when I try to have an include like include("includes/z.php"); nothing shows up...the include doesn't seem to show up. Is there anyway I can fix this?

 

P.S. root/main/a.php and root/includes/z.php  those are the locations of the files...so im not sure what im doing wrong.

 

Thank you for your time;

~L

Link to comment
Share on other sites

<?php include $_SERVER['DOCUMENT_ROOT'] . '/includes/z.php'; ?>

 

that doesn't seem to work, but

include("../includes/z.php");

seems to work for me...if i had a file deeper from the root would i just have it like

 

include("../../../z/z.php

 

~L

Link to comment
Share on other sites

infact thorp i have a question also

 

i had a script which i moved from one server to another and it stopped working.. it was down to the fact i used

<?php include $_SERVER['DOCUMENT_ROOT'] . '/includes/z.php'; ?>

, which was pretty standard in my code.. instead i used

dirname(__FILE__)."/../includes/z.php"

, which seams to work but is their a "standard" ?

Link to comment
Share on other sites

hmm....the whole ../ thing isn't working now...cause when i go to my index the include doesn't show...i have one file called z.php that is my menu, but now it's all messed up...except in the a.php page because it was specified...any help?

Link to comment
Share on other sites

the dirname gives me "/hosted/subs/ulmb.com/i/n/infinitevortex/public_html" without quotes

 

then when i echo it gives me

hosted/subs/ulmb.com/i/n/infinitevortex/public_html/includes/z.php

 

when i put

echo dirname(__FILE__)."/includes/z.php";

 

here is my include

<?php include dirname(__FILE__)."/includes/z.php"; ?>

 

Thank you for your effort thus far

~L

Link to comment
Share on other sites

This is how I do it -->

 

On the root of the server I have folder called "element" the folder where all my includes are.

 

This is a page:

 

<?php

// define page elements
$root = "../element/";

// header include
include ($root.'header.php');

?>
<body>

</body>
<!-- HTML BODY END -->

<!-- Footer Include -->
<?php

// footer must be included
include ($root.'footer.php');

?>

 

This is an example. $root is the path name to the root of the server. If you are editing the index you would leave it empty, if its one directory in its ../element and 2 directories in it would be ../../element.

 

This works for me. I hope it works for you.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.