Page 1 of 1

PHP Page/Address Variables

Posted: Sun Apr 11, 2004 10:07 am
by R_P
When coding in PHP I've always been able to control content by using code like below (file: main.php):

Code: Select all

<?php
if ($nav=="login") {
   include "login_include.php";
} elseif ($nav=="register") {
   include "login_register.php";
} elseif ($nav=="") {
   echo "Main Page";
}
?>
Then going to http://www.myaddress.com/main.php?nav=login would give me just the contents of login_include.php or going to http://www.myaddress.com/main.php would just echo "Main Page." For some reason, on a fresh PHP installation of a new Win2K server running IIS, I cannot do this. For whatever $nav is, I always get "Main Page" no matter what and there are no error messages. Anyone have any idea why this might be? Is there something in PHP.ini I need to fix or is there something I'm doing wrong in code in a new version of PHP? Thanks in advance for the help!

Ryan
[/big_search]

Posted: Sun Apr 11, 2004 11:57 am
by kettle_drum
Sounds like your old version of php still had global variables turned on. In newer version it is turned off by default, you can either turn it back on in your php.ini file, or address your variables according to where they come from, I.E. $_GET[nav]

Posted: Sun Apr 11, 2004 12:05 pm
by d3ad1ysp0rk
change your code to this:

Code: Select all

<?php 
$nav = $_GET['nav'];
if ($nav=="login") { 
   include "login_include.php"; 
} elseif ($nav=="register") { 
   include "login_register.php"; 
} elseif ($nav=="") { 
   echo "Main Page"; 
} 
?>