PHP Page/Address Variables

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
R_P
Forum Newbie
Posts: 1
Joined: Sun Apr 11, 2004 10:07 am
Location: Atlanta

PHP Page/Address Variables

Post 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]
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post 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]
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

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