Page 1 of 1
Should this work, if no 'menu' is in the URL?
Posted: Tue Nov 29, 2011 4:55 am
by simonmlewis
Code: Select all
<?php
function getMenu()
{
$thismenu="includes/menu/".$_GET['menu'].".inc";
include $thismenu;
}
$menu=$_REQUEST['menu'];
if ($menu == NULL) { $menu = "home";}
getMenu();
?>
If the URL is:
http://www.domain.co.uk/index.php?page=home, shouldn't this pull in "home" as the menu file and place it in this section of the page?
If I set it to ".....index.php?page=home&menu=home", it works.
Re: Should this work, if no 'menu' is in the URL?
Posted: Tue Nov 29, 2011 5:06 am
by social_experiment
simonmlewis wrote:houldn't this pull in "home" as the menu file and place it in this section of the page?
No because the script specifies $_GET['menu'] as the required value, not $_GET['page']; same for the $_REQUEST option.
Re: Should this work, if no 'menu' is in the URL?
Posted: Tue Nov 29, 2011 5:09 am
by simonmlewis
So should I be using:
$menu=$_GET['menu']; ??
Re: Should this work, if no 'menu' is in the URL?
Posted: Tue Nov 29, 2011 5:10 am
by maxx99
in this url
http://www.domain.co.uk/index.php?page=home you dont pass menu parameter. And getMenu() always reaches for $_GET not a parameter.
if you want to work with this you need to:
Code: Select all
<?php
function getMenu($menu)
{
$thismenu="includes/menu/".$menu.".inc";
include $thismenu;
}
$menu=$_REQUEST['menu'];
if (empty($menu)) { $menu = "home";}
getMenu($menu);
?>
Btw. its a terrible solution. It may seem secure with the path and file extension

... but it isnt.
If you want to stay as simple as this, you'd better use switch/case.
Code: Select all
$menu=$_REQUEST['menu'];
switch($menu){
case 'books':
$include="includes/books/books.inc";
break;
default:
$include="includes/menu/home.inc";
break;
}
include $include;
Re: Should this work, if no 'menu' is in the URL?
Posted: Tue Nov 29, 2011 5:34 am
by social_experiment
I personally wouldn't use $_REQUEST here; if you know where the value is going to come from, why not use $_GET?
Re: Should this work, if no 'menu' is in the URL?
Posted: Tue Nov 29, 2011 5:38 am
by maxx99
My bad, copy&paste fail. Agree 100%
