ballhogjoni Posted August 22, 2007 Share Posted August 22, 2007 Is it possible to pass a variable by include()ing it? I want to pass one value with a variable to one page to another with out a link or a form. my code on the include() <?php //TRUE means people can see the site, FALSE means the site is under construction $site_on = 'FALSE'; ?> page includeing the include <?php include('http://nnnnnnnnnnn.com/site_on.php'); if ($site_on == 'FALSE') { echo 'the site is down for maintenance...Please check back later.'; } else { ?> This code does not work currently. Quote Link to comment https://forums.phpfreaks.com/topic/66187-solved-passing-variables-with-an-include/ Share on other sites More sharing options...
akitchin Posted August 22, 2007 Share Posted August 22, 2007 that should, in theory, work. try var_dump()ing the $site_on variable after including the file and see what it spits out. Quote Link to comment https://forums.phpfreaks.com/topic/66187-solved-passing-variables-with-an-include/#findComment-331073 Share on other sites More sharing options...
trq Posted August 22, 2007 Share Posted August 22, 2007 You should also be using booleens. eg; <?php //TRUE means people can see the site, FALSE means the site is under construction $site_on = FALSE; ?> and... <?php include('http://nnnnnnnnnnn.com/site_on.php'); if (!$site_on) { echo 'the site is down for maintenance...Please check back later.'; } else { ?> Quote Link to comment https://forums.phpfreaks.com/topic/66187-solved-passing-variables-with-an-include/#findComment-331076 Share on other sites More sharing options...
ballhogjoni Posted August 22, 2007 Author Share Posted August 22, 2007 that should, in theory, work. try var_dump()ing the $site_on variable after including the file and see what it spits out. When I var_dump() it spits out NULL. Quote Link to comment https://forums.phpfreaks.com/topic/66187-solved-passing-variables-with-an-include/#findComment-331099 Share on other sites More sharing options...
akitchin Posted August 22, 2007 Share Posted August 22, 2007 could be because you're including it using the URL rather than the filesystem. also try var_dump()ing the $site_on variable from within the included file and see if that at least spits out the right info. keep in mind you have to run var_dump() AFTER you've assigned it. Quote Link to comment https://forums.phpfreaks.com/topic/66187-solved-passing-variables-with-an-include/#findComment-331102 Share on other sites More sharing options...
ballhogjoni Posted August 22, 2007 Author Share Posted August 22, 2007 I tried the filesystem path, no luck. Also I var_dump()ed in the include and it worked. Came up with bool(false), but I still get NULL on the other page. Quote Link to comment https://forums.phpfreaks.com/topic/66187-solved-passing-variables-with-an-include/#findComment-331142 Share on other sites More sharing options...
akitchin Posted August 22, 2007 Share Posted August 22, 2007 well, you could always try define()ing a variable and see if that works. i don't think scope is an issue, but who knows in this case: <?php define('SITE_ON', FALSE); ?> <?php include('site_on.php'); var_dump(SITE_ON); if(SITE_ON === FALSE) { exit('site down for construction, please eff off for now.'); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/66187-solved-passing-variables-with-an-include/#findComment-331146 Share on other sites More sharing options...
ballhogjoni Posted August 22, 2007 Author Share Posted August 22, 2007 NVM I had the filepath wrong. It works now...thanks for your help. Quote Link to comment https://forums.phpfreaks.com/topic/66187-solved-passing-variables-with-an-include/#findComment-331148 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.