[clug] need another set of eyes - PHP when no variable is passed

David Tulloh david at tulloh.id.au
Thu Mar 30 03:23:12 GMT 2006

Kristy A. Bennett wrote:
> Okay,
> It's just one of those days >:o
> Okay so here's the dilemma.  I have a page - say index.php which has a
> variable 'menu' to be passed back to itself.  This variable is then used
> to call in flash movie (yeah, yeah I know....).  This part was working
> and but I have since broken it again.  However, the problem does not lie
> here.
> I cannot for the life of me work out how to set a default variable if
> one is not passed (eg user goes to index.php as opposed to
> index.php?menu="about").
> I have tried if(!$menu) {blah} and if ($menu=="") {blah}.  Neither work
> - is there any other solution that I have just simply overlooked?

You should be using $_GET['menu'] rather than $menu.  Register globals
is bad and it has been entirely removed from PHP 6.

I think you want to use the isset() function.
if(!isset($_GET['menu']) { do stuff; }
or using register globals, if(!isset($menu)) { do stuff; }


More information about the linux mailing list