Jump to content


Photo

page inside include not calling varible


  • Please log in to reply
3 replies to this topic

#1 leeming

leeming
  • Members
  • PipPipPip
  • Advanced Member
  • 93 posts

Posted 01 August 2006 - 07:59 PM

im totaly sure ive always been able to do this...
$var = 1;

include("file.php");

echo $var;
where file.php...
echo 'var is: '.$var.' :inside include<BR>';

where it should output

var is: 1 :inside include
1



but the following code i did doesnt let me, (is there a setting in sum file that turns this on/off? because i've had trouble where the server admin has changed things on all sites instead of just one...)
include($site_link."/inc/functions.inc.php");

//...code between.. nothing to do with $page....

if(in_array("$page", $public_pages))
{
  include($site_link."/pub-".$page.".php");
    die("goo::$page::gooo");
}
functions.inc.php contains (i even commented every thing out apart form this line)
  print"goo::$page::gooo";

all i get from them is

goo::::gooo
goo::main::gooo


Im not perfect ;) lol

#2 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 01 August 2006 - 08:09 PM

Are you sure that the statement

print"goo::$page::gooo";

in the included file is NOT within a function? Because then $page would be a different variable (private to the function) from the one you set.

ROnald  ;D

RTFM is an almost extinct art form, it should be subsidized.

#3 leeming

leeming
  • Members
  • PipPipPip
  • Advanced Member
  • 93 posts

Posted 01 August 2006 - 08:26 PM

Are you sure that the statement

print"goo::$page::gooo";

in the included file is NOT within a function? Because then $page would be a different variable (private to the function) from the one you set.

ROnald  ;D


no no its not in a function.. i just put it one of the 1st include files on my page 2 test it my theory (which took a while y my code wasnt working)

its just a plain variable that works in the main page.. but as soon as its inside an include/require it stops existance....


heres another try.. (to check there is no mixing with values)
//main page
$leeming = "woot";

include($site_link."/inc/functions.inc.php");

die($leeming);




//include file

if($leeming)
{
  print"'leeming' is here<BR>";
}
elseif(isset($leeming))
{
  print"'leeming' is set<BR>";
}
else
{
  print"no to all the above<BR>";
}

outputs,

no to all the above
woot


Im not perfect ;) lol

#4 leeming

leeming
  • Members
  • PipPipPip
  • Advanced Member
  • 93 posts

Posted 01 August 2006 - 08:31 PM

humm i figgured it out with this code

$leeming = "woot";

include($site_link."/inc/functions.inc.php");
include("inc/functions.inc.php");
include "inc/functions.inc.php" ;

die($site_link);

$site_link, is the full address... so it wasnt passing the variable
Im not perfect ;) lol




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users