salvador2001 Posted April 7, 2006 Share Posted April 7, 2006 hi all,I am very noob with PHP and i cant get this script working right.Now i got a variable error on the section "load in directory"Can anyone please adjust this script for me ? <?php // load existing pages if(isset($_GET['load'])) { switch($_GET['load']) { case 'news': case 'about': case 'members': $load = $_GET['load']; break; default: $load = 'welcome'; } } // load in root directory if (is_file($load . ".php")) { include($load . ".php"); } // load errorpage else { include("error404.php"); } ?> Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted April 7, 2006 Share Posted April 7, 2006 What is the error message you are getting? PLease could you post them here. Quote Link to comment Share on other sites More sharing options...
salvador2001 Posted April 7, 2006 Author Share Posted April 7, 2006 Notice: Undefined variable: load in e:\webserver\.........\script.php on line 19Line 19 is the part with this code if (is_file($load . ".php")) { include($load . ".php"); } Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted April 7, 2006 Share Posted April 7, 2006 The problem is that if $_GET['load'] isn't set, then the variable $load isn't defined. Do this before your switch to make sure that $load is always defined:[code]<?php if (!isset($_GET['load'])) $load = 'welcome'; ?>[/code] or something similar.Ken Quote Link to comment Share on other sites More sharing options...
Yesideez Posted April 7, 2006 Share Posted April 7, 2006 By the looks of it you've not set $load to be anything before its used/checked.Try using this:[code]if (!empty($load)) { if (is_file($load . ".php")) { include($load . ".php"); }}[/code] Quote Link to comment Share on other sites More sharing options...
salvador2001 Posted April 8, 2006 Author Share Posted April 8, 2006 Thanks a lot !, the error message is gone.But now there is one thing left, it keeps loading the errorpage at start while it should display the welcome page. Its a dynamic page so he doesnt load the content it should.any idea what is going wrong ?This is the script so far;<?php // only this pages are allowed if(isset($_GET['load'])) { switch($_GET['load']) { case 'news': case 'about': case 'members': $load = $_GET['load']; break; default: $load = 'welcome'; } } // load files in rootdirectory if (!empty($load)) { if (is_file($load . ".php")) { include($load . ".php"); }} // loading error pageelse { include("error404.php"); } ?> Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted April 8, 2006 Share Posted April 8, 2006 If you had implemented my suggestion instead of the one from [b]Yesideez[/b] you it would be working.Here is my suggestion again:[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Do this before your switch to make sure that $load is always defined:[code]<?php if (!isset($_GET['load'])) $load = 'welcome'; ?>[/code][/quote]Ken Quote Link to comment Share on other sites More sharing options...
salvador2001 Posted April 8, 2006 Author Share Posted April 8, 2006 Thanks, someone got it solved for me and its working. For other people this could be a good example so i post the working script here. [code]<?php // only this pages are allowed if(isset($_GET['load'])) { switch($_GET['load']) { case 'news': case 'about': case 'members': $load = $_GET['load']; break; default: $load = 'welcome'; } } else { $load = 'welcome'; // -- if $_GET['load'] is not defined} // load files in rootdirectory if (is_file($load . ".php")) { include($load . ".php"); } // loading errorpage else { include("error404.php"); } ?> [/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.