Page 1 of 1
rub in url not working for include.
Posted: Sat Jul 29, 2006 3:05 pm
by ircluzar
Well, i'm making a website and i want it to be the cleanest possible so i used includes and rubs in php.
Here's my code for the include part in my index:
Code: Select all
<?
if ($rub == NULL) {
$rub = News;
}
include("./$rub.php");
?>
I first thought that it worked when i got on the root but after i
used my links in my menu i realized the rub was always null !
in fact, if i strip out the
Code: Select all
if ($rub == NULL) {
$rub = News;
}
it just gives me errors when i try my pages like
index.php?rub=Forum
index.php?rub=Chat
index.php?rub=News
it writes me that:
Warning: include(./.php) [function.include]: failed to open stream: No such file or directory in /var/www/index.php on line 60
Warning: include() [function.include]: Failed opening './.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/index.php on line 60
well, my rub is always NULL whatever i write in the url and i don't know why.
why does this F****G rub is always null ???
thanks for awnsering me (if someone does it)
Posted: Sat Jul 29, 2006 3:05 pm
by feyd
Run the following in a new file and tell us the results please.
Code: Select all
<?php
$neg = array(0, false, '', null, 'off');
$ve = phpversion();
$os = PHP_OS;
$er = intval(error_reporting());
$rg = (in_array(strtolower(ini_get('register_globals')), $neg) ? 'Off' : 'On');
$de = (in_array(strtolower(ini_get('display_errors')), $neg) ? 'Off' : 'On');
$so = (in_array(strtolower(ini_get('short_open_tag')), $neg) ? 'Off' : 'On');
$le = '';
$cli = (php_sapi_name() == 'cli');
$eol = ($cli ? "\n" : "<br />\n");
$gle = get_loaded_extensions();
$rows = array();
$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)) . "\n";
}
if ($cli)
{
$le = $eol . $le;
}
else
{
$le = '<pre>' . $le . '</pre>';
}
$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;
}
}
$er = $er . ' (' . implode(' | ', $e) . ')';
if (!$cli)
{
echo '<html><head><title>quick info</title></head><body>' . "\n";
}
echo 'PHP Version: ' . $ve . $eol;
echo 'PHP OS: ' . $os . $eol;
echo 'Error Reporting: ' . $er . $eol;
echo 'Register Globals: ' . $rg . $eol;
echo 'Short Tags: ' . $so . $eol;
echo 'Display Errors: ' . $de . $eol;
echo 'Loaded Extensions:' . $le . $eol;
if (!$cli)
{
echo '</body></html>' . "\n";
}
?>
Posted: Sat Jul 29, 2006 3:35 pm
by ircluzar
It gives me that:
Code: Select all
PHP Version: 5.1.4-0.1
PHP OS: Linux
Error Reporting: 2039 (E_USER_NOTICE | E_USER_WARNING | E_USER_ERROR | E_COMPILE_WARNING | E_COMPILE_ERROR | E_CORE_WARNING | E_CORE_ERROR | E_PARSE | E_WARNING | E_ERROR)
Register Globals: Off
Short Tags: On
Display Errors: On
Loaded Extensions:
xmlwriter libxml xml wddx
tokenizer sysvshm sysvsem sysvmsg
standard SimpleXML sockets soap
SPL shmop session Reflection
posix mime_magic mbstring iconv
hash gettext ftp filepro
exif dom dba date
ctype calendar bz2 bcmath
zlib pcre openssl xmlreader
apache2handler mysql
Posted: Sat Jul 29, 2006 3:44 pm
by feyd
As you may see, register globals is off -- a good thing. Therefore $_GET['rub'] is the proper way to access the url value.
Posted: Sat Jul 29, 2006 4:14 pm
by ircluzar
Well, i want to use the rub include thing so, what should i do?
Posted: Sat Jul 29, 2006 4:24 pm
by feyd
Posted: Sat Jul 29, 2006 5:41 pm
by ircluzar
thanks, my problem is now solved ^^