Reputation: 5
im going to make an algorithm menu with this code on index.php
<?php
$menu=$_GET[menu];
$file=$_GET[file];
if(!isset($menu))
{
$menu="home";
}
if(($menu=="'")||($menu="-")||($menu="/"))
{
$menu="home";
}
switch($menu)
{
case'home':
$file="isi/home.html";
break;
case'profile':
$file="isi/profile.html";
break;
case'gallery':
$file="isi/lihat_bukutamu.php";
break;
case'download':
$file="isi/lihat_bukutamu.php";
break;
case'contact':
$file="isi/buku_tamu.php";
break;
}
include"header.php";
include"menu.php";
include"content.php";
include"footer.php";
?>
but but when i try this script it show me
Notice: Use of undefined constant menu - assumed 'menu' in C:\xampp\htdocs\layout\index.php on line 2
Notice: Undefined index: menu in C:\xampp\htdocs\layout\index.php on line 2
Notice: Use of undefined constant file - assumed 'file' in C:\xampp\htdocs\layout\index.php on line 3
Notice: Undefined index: file in C:\xampp\htdocs\layout\index.php on line 3
this is the menu.php
<div id="menu-content">
<div id="menu">
<h3 class ="judul_1">Main Menu</h3>
<ul>
<li><a href="index.php?menu=home">Home</a></li>
<li><a href="index.php?menu=profile">Profile</a></li>
<li><a href="index.php?menu=gallery">Gallery</a></li>
<li><a href="index.php?menu=download">Download</a></li>
<li><a href="index.php?menu=contact">Contact</a></li>
</ul>
</div>
can you solve it?
Upvotes: 0
Views: 154
Reputation: 606
First thing, you are missing quotes in $_GET[menu]. And another thing that you should also use isset or empty always while getting request params.
Example:
$menu= !empty($_GET["menu"]) ? $_GET["menu"] : '';
Upvotes: 0
Reputation: 2844
Adding quotes as pointed out in other answers will eliminate notices, but doesn't change how the script work (PHP would add the quotes nevertheless).
You are not doing anything with $file
variable. I guess you would like to include it somewhere between header and footer.
include "header.php";
include "menu.php";
include "content.php";
include $file;
include "footer.php";
CAUTION I would not recommend passing file
through GET/POST, as an attacker could make the script include/display arbitrary file from your filesystem if not properly secured.
Upvotes: 0
Reputation: 4275
You are specifying Constant in array which is not defined. Specify it as string
Change this
$menu=$_GET[menu];
$file=$_GET[file];
to
$menu=$_GET['menu'];
$file=$_GET['file'];
Hope this helps you
Upvotes: 1
Reputation: 100195
add quotes around your variable, as:
$menu=$_GET['menu'];
$file=$_GET['file'];
...
Upvotes: 2