Page 1 of 1
Variables not passing into an include
Posted: Wed Jan 10, 2007 8:43 am
by Citizen
One my base php file, I define a variable, $sads = 1;.
Then I include a file /ads.php
In ads.php, I echo"$sads"; and nothing comes up. I've been googling this for about a half hour and cant find any reason whe the variable wouldnt transfer.
Any ideas?
Posted: Wed Jan 10, 2007 8:47 am
by Grim...
Are you defining the variable in a function?
Posted: Wed Jan 10, 2007 8:48 am
by Citizen
Nope, should i be?
Edit: here's the exact code:
Code: Select all
<?
$sads = 1;
include('newend.php')
?>
in newend.php:
Posted: Wed Jan 10, 2007 9:12 am
by Kieran Huggins
First of all, you need a semicolon after your inlcude statement.
Also, you shouldn't be putting quotes around your variable.
Check out the man pages for each function your using and check out the examples.
Posted: Wed Jan 10, 2007 9:13 am
by shiznatix
try making $sads = '1'; (notice the quotes)
Posted: Wed Jan 10, 2007 9:16 am
by mattbee
Edit (missed the bleeding obvious!)
You say you want to include
/ads.php
but your code says you are including
newend.php
Check the file names first!
/Edit
As long as you are enclosing the echo statement in php tags I see no reason that it wouldn't work.
Try using
instead of
You may not have short tags enabled.
Posted: Wed Jan 10, 2007 9:24 am
by Citizen
New code:
Code: Select all
<?php
$sads = '1';
include('newend.php');
?>
on newend.php...
<?php
echo "$sads";
?>
With nothing showing still.
Posted: Wed Jan 10, 2007 9:41 am
by Kieran Huggins
when I mentioned not putting quotes around your variable, I meant:
Posted: Wed Jan 10, 2007 9:44 am
by Citizen
New code:
Code: Select all
<?php
$sads = '1';
include('newend.php');
?>
on newend.php...
Nothing being echo'd still.
Posted: Wed Jan 10, 2007 9:50 am
by Grim...
That's... wierd.
Does this work:
Code: Select all
<?php
$sads = '1';
include('newend.php');
echo $sads;
?>
Posted: Wed Jan 10, 2007 10:28 am
by feyd
Run the following in a new file and tell us the results please.
Code: Select all
<?php
$neg = array('off', 0, false, '', null);
$flags = array(
'Register Globals' => 'register_globals',
'Short Tags' => 'short_open_tag',
'Display Errors' => 'display_errors',
'Magic Quotes GPC' => 'magic_quotes_gpc',
'Magic Quotes Runtime' => 'magic_quotes_runtime',
'Magic Quotes Sybase' => 'magic_quotes_sybase',
);
$ve = phpversion();
$os = PHP_OS;
$er = intval(error_reporting());
foreach ($flags as $n => $v)
{
$flags[$n] = (in_array(strtolower(ini_get($v)), $neg) ? 'Off' : 'On');
}
$cli = (php_sapi_name() == 'cli');
$eol = "\n";
$gle = get_loaded_extensions();
$rows = array();
$le = '';
$wide = 4;
$j = count($gle);
$pad = $wide - $j % $wide;
$len = max(array_map('strlen', $gle));
$func = create_function('$a', 'return str_pad($a, ' . intval($len) . ');');
$gle = array_map($func, $gle);
for($i = 0; $i < $j; $i += $wide)
{
$le .= ' ' . implode(' ', array_slice($gle, $i, $wide)) . $eol;
}
$ec = array(
'E_STRICT' => 2048, 'E_ALL' => 2047, 'E_USER_NOTICE' => 1024,
'E_USER_WARNING' => 512, 'E_USER_ERROR' => 256, 'E_COMPILE_WARNING' => 128,
'E_COMPILE_ERROR' => 64, 'E_CORE_WARNING' => 32, 'E_CORE_ERROR' => 16,
'E_NOTICE' => 8, 'E_PARSE' => 4, 'E_WARNING' => 2, 'E_ERROR' => 1,
);
$e = array();
$t = $er;
foreach ($ec as $n => $v)
{
if (($t & $v) == $v)
{
$e[] = $n;
$t ^= $v;
}
}
if (ceil(count($ec) / 2) + 1 < count($e))
{
$e2 = array();
foreach ($ec as $n => $v)
{
if (!in_array($n, $e) and $n != 'E_ALL')
{
$e2[] = $n;
}
}
$er = $er . ' ((E_ALL | E_STRICT) ^ ' . implode(' ^ ', $e2) . '))';
}
else
{
$er = $er . ' (' . implode(' | ', $e) . ')';
}
if (!$cli)
{
echo '<html><head><title>quick info</title></head><body><pre>', $eol;
}
echo 'PHP Version: ', $ve, $eol;
echo 'PHP OS: ', $os, $eol;
echo 'Error Reporting: ', $er, $eol;
foreach ($flags as $n => $v)
{
echo $n, ': ', $v, $eol;
}
echo 'Loaded Extensions:', $eol, $le, $eol;
if (!$cli)
{
echo '</pre></body></html>', $eol;
}
?>
Posted: Wed Jan 10, 2007 10:29 am
by Citizen
Grim... wrote:That's... wierd.
Does this work:
Code: Select all
<?php
$sads = '1';
include('newend.php');
echo $sads;
?>
Yup, that works.
Posted: Wed Jan 10, 2007 10:41 am
by RobertGonzalez
Run the script feyd posted. That tells us a lot. Then run this...
Code: Select all
<?php
ini_set('error_reporting', E_ALL);
ini_set('display_errors', 1);
$sads = 1;
require_once 'newend.php';
?>
newend.php
Code: Select all
<?php
if (isset($sads))
{
echo $sads;
}
else
{
die('I am dying inside of the include!');
}
?>
Posted: Wed Jan 10, 2007 12:16 pm
by Citizen
Results from feyd's
PHP Version: 5.1.4
PHP OS: Linux
Error Reporting: 2039 ((E_ALL | E_STRICT) ^ E_STRICT ^ E_NOTICE))
Register Globals: Off
Short Tags: On
Display Errors: On
Magic Quotes GPC: On
Magic Quotes Runtime: Off
Magic Quotes Sybase: Off
Loaded Extensions:
xmlwriter libxml dom xmlreader
xml tokenizer standard SimpleXML
SPL session sockets PDO
SQLite Reflection posix mysqli
mysql iconv hash gd
ftp date ctype calendar
bcmath zlib pcre apache
Zend Optimizer
I'll test that other page now.
Posted: Wed Jan 10, 2007 1:13 pm
by volka
Citizen wrote:Edit: here's the exact code:
Code: Select all
<?
$sads = 1;
include('newend.php')
?>
in newend.php:
Let's make it a littlebit more interesting
Code: Select all
<?php // main.php
error_reporting(E_ALL);
ini_set('display_errors', true);
$sads = 1;
echo '<div>file: ', __FILE__, "</div>\n";
require 'newend.php';
echo '<hr /><div>sads: ', $sads, "</div>\n";
?>
Code: Select all
<?php // newend.php
echo '<div>file: ', __FILE__, "</div>\n";
echo '<pre>callstack: '; debug_print_backtrace(); echo "</pre>\n";
echo "<pre>defined vars: \n";
$v = get_defined_vars();
ksort($v, SORT_STRING);
foreach($v as $name=>$var) {
echo $name, '=>', gettype($var), "\n";
}
echo "</pre>\n";
echo '<hr /><div>sads: ', $sads, "</div>\n";
?>
what does that print?