rub in url not working for include.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ircluzar
Forum Newbie
Posts: 4
Joined: Sat Jul 29, 2006 2:43 pm

rub in url not working for include.

Post 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)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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";
}

?>
ircluzar
Forum Newbie
Posts: 4
Joined: Sat Jul 29, 2006 2:43 pm

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
ircluzar
Forum Newbie
Posts: 4
Joined: Sat Jul 29, 2006 2:43 pm

Post by ircluzar »

Well, i want to use the rub include thing so, what should i do?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

this may be of interest.
ircluzar
Forum Newbie
Posts: 4
Joined: Sat Jul 29, 2006 2:43 pm

Post by ircluzar »

thanks, my problem is now solved ^^
Post Reply