holyearth Posted July 7, 2007 Share Posted July 7, 2007 Hello, In my page, I am sending this parameter ... target.php?day=monday I need to tell php that if day = monday then include "monday.txt" if day = Tuesday then include "tuesday.txt" But, if day = blank or day = is not specified then include "default.txt" I only know how to do a basic include so I am stomped on this one. Thanks everyone, this forum rocks! Quote Link to comment Share on other sites More sharing options...
hackerkts Posted July 7, 2007 Share Posted July 7, 2007 You can try if and switch statement. Quote Link to comment Share on other sites More sharing options...
MemphiS Posted July 7, 2007 Share Posted July 7, 2007 <?php $getDay = strip_tags(addslashes($_GET['day'])); if (isset($getDay)){ // if 'day' is set if (!ctype_alpha($getDay)){ // Checks for Alphabetical letters $getDay = "default"; // default to index when wrong } $allowed = array("Monday","Tuesday","Wednesday","Thursday","Firday","Saturday","Sunday"); // place your allowed pages in the array(); if (!in_array($getDay,$allowed,true)){ // Checks the page $getDay = "default"; // default to index when wrong } require_once("$getDay.txt"); }else{ require_once("default.txt"); } ?> Quote Link to comment Share on other sites More sharing options...
Yesideez Posted July 7, 2007 Share Posted July 7, 2007 Another way is this: <?php $day=strtolower($_GET['day']); switch ($day) { case 'monday';$useday='monday';break; case 'tuesday';$useday='tuesday';break; case 'wednesday';$useday='wednesday';break; case 'thursday';$useday='thursday';break; case 'friday';$useday='friday';break; case 'saturday';$useday='saturday';break; case 'sunday';$useday='sunday';break; default:$useday='error'; } include($useday.'.txt'); ?> If any day is invalid then error.txt is included instead. error.txt is also included if nothing is specified on the URL. EDIT: Changed .php to .txt - misread the question Quote Link to comment Share on other sites More sharing options...
holyearth Posted July 7, 2007 Author Share Posted July 7, 2007 Thanks MemphiS and Yesideez... I ended up choosing yours Yesideez... One last question... I need to make one change... I want to tell the script that if there is a day2= switch then dont include anything.... Quote Link to comment Share on other sites More sharing options...
holyearth Posted July 7, 2007 Author Share Posted July 7, 2007 No matter what day2= ... as long as there is a day2= something then dont include anything Perhaps a if day2 == something then die ? Quote Link to comment Share on other sites More sharing options...
Yesideez Posted July 7, 2007 Share Posted July 7, 2007 <?php if (empty($_GET['day2'])) { $day=strtolower($_GET['day']); switch ($day) { case 'monday';$useday='monday';break; case 'tuesday';$useday='tuesday';break; case 'wednesday';$useday='wednesday';break; case 'thursday';$useday='thursday';break; case 'friday';$useday='friday';break; case 'saturday';$useday='saturday';break; case 'sunday';$useday='sunday';break; default:$useday='error'; } include($useday.'.txt'); } ?> Quote Link to comment Share on other sites More sharing options...
holyearth Posted July 8, 2007 Author Share Posted July 8, 2007 Yesideez, How can I change it to pull the .txt file from a directory... example ... include(days/$useday.'.txt'); That didnt work for me... Quote Link to comment Share on other sites More sharing options...
Yesideez Posted July 8, 2007 Share Posted July 8, 2007 include('days/'.$useday.'.txt'); Quote Link to comment Share on other sites More sharing options...
holyearth Posted July 8, 2007 Author Share Posted July 8, 2007 Thanks Yesideez ... MUCH appreciated! 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.