well i just started getting into PHP recently. I'm very familiar with HTML and thought i should venture within the dynamic side of web design.
Here's what i need help with. i'm working on a navigation script that hides the URL(index.php?page=one). Yes, i know this is basic stuff... But when i made one script friend told me i was passing an undeclared variable and chose not to tell me how or why. Here's what i got so far.
<?PHP
# $_GET to variable
# "page.php?page=example"
$file = $_GET['page'];
# file extention
$ext = ".php";
# full url
$full = $file . $ext;
include ($full);
exit;
?>
Down fall to this snippet of code is, you can just type in anything random at the end and travel throughout my web server(i think). So i added file_exist to it.
<?PHP
# filename
$file = $_GET['page'];
# file extention
$ext = ".php";
# full name
$full = $file . $ext;
# 404 page
$404 = "404.php";
# file exist
if(file_exist($full))
{
include($full);
exit;
}
else
{
include($404);
exit;
}
?>
But my friend still says i'm passing an undeclared variable. So how can i do this? To make it more "Secure" i made it into a switch.
<?PHP
# page name
$page = $_GET['page'];
# switch
# to get page.php?page=one
switch($page)
{
default: include('home.php'); exit;
case one: include('one.php'); break;
}
?>
But is there a way so i don't have to edit this page and add it in? I'm a noob at this and i'm lost, lol. Thanks for anyhelp ;D