Jump to content

Include() Fail?


RandomClown

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);?>

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.

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");

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).

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...