Variables not passing into an include
Moderator: General Moderators
Variables not passing into an include
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?
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?
Nope, should i be?
Edit: here's the exact code:
in newend.php:
Edit: here's the exact code:
Code: Select all
<?
$sads = 1;
include('newend.php')
?>Code: Select all
echo"$sads";- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
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.
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
Code: Select all
<?phpCode: Select all
<?New code:
on newend.php...
<?php
echo "$sads";
?>
With nothing showing still.
Code: Select all
<?php
$sads = '1';
include('newend.php');
?><?php
echo "$sads";
?>
With nothing showing still.
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
when I mentioned not putting quotes around your variable, I meant:
Code: Select all
<?php
echo $sads;
?>New code:
on newend.php...
Nothing being echo'd still.
Code: Select all
<?php
$sads = '1';
include('newend.php');
?>Code: Select all
<?php
echo $sads;
?>That's... wierd.
Does this work:
Does this work:
Code: Select all
<?php
$sads = '1';
include('newend.php');
echo $sads;
?>- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
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;
}
?>Yup, that works.Grim... wrote:That's... wierd.
Does this work:Code: Select all
<?php $sads = '1'; include('newend.php'); echo $sads; ?>
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Run the script feyd posted. That tells us a lot. Then run this...
newend.php
Code: Select all
<?php
ini_set('error_reporting', E_ALL);
ini_set('display_errors', 1);
$sads = 1;
require_once 'newend.php';
?>Code: Select all
<?php
if (isset($sads))
{
echo $sads;
}
else
{
die('I am dying inside of the include!');
}
?>Results from feyd's
I'll test that other page now.
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.
Let's make it a littlebit more interestingCitizen wrote:Edit: here's the exact code:
in newend.php:Code: Select all
<? $sads = 1; include('newend.php') ?>
Code: Select all
echo"$sads";
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";
?>