Jump to content

[SOLVED] passing variables with an include()?


ballhogjoni

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/66187-solved-passing-variables-with-an-include/
Share on other sites

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 {
?>

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.

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.');
}
?>

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.