brent123456 Posted June 5, 2007 Share Posted June 5, 2007 I am working on a website. I have one index.php page that I am using "?do=dosomething" in the url link like http://www.index.com?do=showthingpage. Then I am using a switch statement to check what the do is and switch($_GET['do']) then using "<? case showthingpage: ($isloggedin) ? require_once(/showthingpage.php) : require_once(/anon.php) ?>" to load the required page into my main div. I am using about 20 case statements to do this for about 20 pages for the site. Is it alright to do it this way and just use one index.php page then load the pages into the div or should I have a page for each one. I though it would be easier to maintain this way? Could someone help me with some advise? thanks ??? Quote Link to comment https://forums.phpfreaks.com/topic/54310-solved-correct-way-require_once/ Share on other sites More sharing options...
The Little Guy Posted June 5, 2007 Share Posted June 5, 2007 Want to paste some code? (use the code bb tags) Quote Link to comment https://forums.phpfreaks.com/topic/54310-solved-correct-way-require_once/#findComment-268546 Share on other sites More sharing options...
Yesideez Posted June 5, 2007 Share Posted June 5, 2007 Personally I'd split the index file into smaller files if just to make it easier to maintain. The other reason is that if for some reason the 'do' parameter isn't supplied you could get the wrong page being served. Quote Link to comment https://forums.phpfreaks.com/topic/54310-solved-correct-way-require_once/#findComment-268548 Share on other sites More sharing options...
brent123456 Posted June 5, 2007 Author Share Posted June 5, 2007 Thanks, I put in a case for that as well case "": require_once(main.php) Should I be worried about security or anything like that? Quote Link to comment https://forums.phpfreaks.com/topic/54310-solved-correct-way-require_once/#findComment-268567 Share on other sites More sharing options...
trq Posted June 5, 2007 Share Posted June 5, 2007 There should be no need for 20 something case statements. Anytime you see repetativeness in your code, your probably not doing something right. <?php $valid = array('page1','page2','page3'); // store an array of valid pages. Needed for security. if (isset($_GET['do'])) { if (in_array($_GET['do'],$valid)) { require_once $_GET['do'].'.php'; exit(); } } require_once 'main.php'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/54310-solved-correct-way-require_once/#findComment-268576 Share on other sites More sharing options...
brent123456 Posted June 6, 2007 Author Share Posted June 6, 2007 How would I stop a user from calling the page in the include folder directly? One that I have used in the require once? If if was a form script. Quote Link to comment https://forums.phpfreaks.com/topic/54310-solved-correct-way-require_once/#findComment-268903 Share on other sites More sharing options...
trq Posted June 6, 2007 Share Posted June 6, 2007 If if was a form script. I'll assume that was... If it was a form script. If you have scripts that should only be requested via a form simply enclose them in a conditional to check they where posted to. eg; <?php if (isset($_POST['submit'])) { // safe to say A form posted to this script } ?> Quote Link to comment https://forums.phpfreaks.com/topic/54310-solved-correct-way-require_once/#findComment-268962 Share on other sites More sharing options...
brent123456 Posted June 6, 2007 Author Share Posted June 6, 2007 Thanks thorpe you have been a big help. I was kind of wondering what I could do to stop a user if they call the page directly like http://www.index.php/includes/add_address.php instead of using the link supplied by the page output in require_once $_GET['do'].'.php'; . If they go directly to the page then it doesn't get the proper $_GET variables that I have supplied in the link to the page. Some of my pages have http://www.index.php?do=add_address&userid=$userid links. If someone calls the script directly in the includes file it doesn't get this id information and generates a ton of errors when the page is submitted. Thank you for you help. Quote Link to comment https://forums.phpfreaks.com/topic/54310-solved-correct-way-require_once/#findComment-269099 Share on other sites More sharing options...
Dragen Posted June 6, 2007 Share Posted June 6, 2007 use an isset to check. <?php if(!isset($_GET['userid'] || !isset($_GET['$othervariable']){ echo 'Error: get method not set etc....'; exit; }else{ //output page } ?> Quote Link to comment https://forums.phpfreaks.com/topic/54310-solved-correct-way-require_once/#findComment-269102 Share on other sites More sharing options...
brent123456 Posted June 6, 2007 Author Share Posted June 6, 2007 Did I mention how awesome you people are? Thanks That will work great Quote Link to comment https://forums.phpfreaks.com/topic/54310-solved-correct-way-require_once/#findComment-269103 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.