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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.