Jump to content

Include() Fail?


RandomClown
 Share

Recommended Posts

ok, this might be a noob question.I was trying to use the include function but failed.I looked through lots of pages fitting my syntax to their design if possible, but still fail.How would I get this to work?

<?php$page="/Projects/Posts/Test.php";include($page);?>

Edited by RandomClown
Link to comment
Share on other sites

is your include path correct?

$page="/Projects/Posts/Test.php";

if the Projects folder is in the same folder as your php script thennotice the leading slash in your path

//if the Projects folder is in the same folder as your php script//it should be like this$page="Projects/Posts/Test.php";//and NOT like this//this is WRONG$page="/Projects/Posts/Test.php";

Link to comment
Share on other sites

let's check everything else while we're at it.What makes you sure it's failing? What behavior did you expect? What did you get instead? Were their error or warning messages? The your page generate anything at all? (Was it supposed to) Did you get a totally blank screen? What makes you certain the include statement is to blame?

Link to comment
Share on other sites

Thanks for your reply. Wasn't sure where to start with this post.I am sure it fails since the rest of the php script worksThe path is correct, the beginning slash to start from the root.Here is the exact script, which is in some sub-folder:

	<div class="Border HovBooa PadAllExR">		<div>			<img onclick="ToggleVis(this,'<?php echo $_GET["ID"];?>');" style="cursor:pointer" src="/src/Functions/JS/ToggleVis/-.png" alt="-" />			<span class="Sec2"><?php echo $_GET["Title"];?>:</span>		</div>		<div class="PadL" id="<?php echo $_GET["ID"];?>">			<?php echo "lolcats";include("/index-Bar.php");?>		</div>	</div>f

If I open the page like so:

PageMainSection.php?ID=ChangeLog&Title=Change Log

Here is the output:

	<div class="Border HovBooa PadAllExR">		<div>			<img onclick="ToggleVis(this,'ChangeLog');" style="cursor:pointer" src="/src/Functions/JS/ToggleVis/-.png" alt="-" />			<span class="Sec2">Change Log:</span>		</div>		<div class="PadL" id="ChangeLog">			lolcats		</div>	</div>f

The output is everything except the content of the file [no, its not empty]Hope this helps.

Edited by RandomClown
Link to comment
Share on other sites

nm, i read that wrong.so your included file is in the root directory?
In this example, yep.I do hope to move it into sub-folders though.BTW I am using sourceforge.net:[Page]if you go to the include file, you will see its there:http://horc.sourceforge.net/index-Bar.php[see the page source] Edited by RandomClown
Link to comment
Share on other sites

Note - when you refer to the root directory on the server, that refers to the system root (not the document root).

Link to comment
Share on other sites

Include the file relative to the current location, or if you know how the system is organized, then you can do it relative to the system root:include("../file.php");orinclude("/apache/sites/mydomain.com/www/file.php");

Edited by Ingolme
Link to comment
Share on other sites

is Index-Bar.php only supposed to display two empty div's that you can click on?
lol that was only a test. I dont plan to use it on that PHP file. What I plan to use it on does not exist yet.
Include the file relative to the current location, or if you know how the system is organized, then you can do it relative to the system root:include("../file.php");orinclude("/apache/sites/mydomain.com/www/file.php");
ohh I think I get it now.**Testing**IT WORKS!!I did
<?php echo "lolcats";include("/home/groups/h/ho/horc/htdocs/".$_GET["Content"]);?>

Thanks a bunch everyone

Link to comment
Share on other sites

Note: you can use the $_SERVER["DOCUMENT_ROOT"] superglobal index to quickly access your document root (which will also change when you move servers).

Edited by Synook
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...