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
https://forums.phpfreaks.com/topic/61042-help-on-includesnot-linking-corrrectly/
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" ?

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.