undefined index help

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

andylyon87
Forum Contributor
Posts: 168
Joined: Sat Jan 31, 2004 5:31 am
Location: Dundee

Post by andylyon87 »

hey guys just thought Id get your opinion is this any good now. Thanks for the help so far has been awesome.

Code: Select all

$id = isset($_GET['id']) ? $_GET['id'] : 'home';
				if($id){
    				$id = isset($_GET['id']);
    				if (ctype_alnum($id)){
        				$file = "php/$id.php";
        				if(file_exists($file)){
            				include $file;
        				}else{
            				echo '<p class="center"> The page: <span class="bold">' . $id . '.php</span> you requested is unavailable at the present time please try refreshing the page or try again later, your error has been logged and the problem will be fixed shortly.</p>';
        				}
    				}else{
        				include 'php/home.php';
    				}
				}
have used bits of everyones advice hope its decent let me know if you think its too messy.

Andy
andylyon87
Forum Contributor
Posts: 168
Joined: Sat Jan 31, 2004 5:31 am
Location: Dundee

Post by andylyon87 »

yeh I realised the above didnt actually work and edited it down to the below, which (as it happens) works:

Code: Select all

if(isset($_GET['id'])){
    				$id = isset($_GET['id']) ? $_GET['id'] : 'home';
    				if (ctype_alnum($id)){
        				$file = "php/$id.php";
        				if(file_exists($file)){
            				include $file;
        				}else{
            				echo '<p class="center"> The page: <span class="bold">' . $id . '.php</span> you requested is unavailable at the present time please try refreshing the page or try again later, your error has been logged and the problem will be fixed shortly.</p>';
        				}
    				}else{
        				include 'php/home.php';
    				}
				}
Post Reply