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! Link to comment https://forums.phpfreaks.com/topic/58834-solved-include-help/ Share on other sites More sharing options...
hackerkts Posted July 7, 2007 Share Posted July 7, 2007 You can try if and switch statement. Link to comment https://forums.phpfreaks.com/topic/58834-solved-include-help/#findComment-291884 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"); } ?> Link to comment https://forums.phpfreaks.com/topic/58834-solved-include-help/#findComment-291885 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 Link to comment https://forums.phpfreaks.com/topic/58834-solved-include-help/#findComment-291898 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.... Link to comment https://forums.phpfreaks.com/topic/58834-solved-include-help/#findComment-292003 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 ? Link to comment https://forums.phpfreaks.com/topic/58834-solved-include-help/#findComment-292046 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'); } ?> Link to comment https://forums.phpfreaks.com/topic/58834-solved-include-help/#findComment-292064 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... Link to comment https://forums.phpfreaks.com/topic/58834-solved-include-help/#findComment-292518 Share on other sites More sharing options...
Yesideez Posted July 8, 2007 Share Posted July 8, 2007 include('days/'.$useday.'.txt'); Link to comment https://forums.phpfreaks.com/topic/58834-solved-include-help/#findComment-292526 Share on other sites More sharing options...
holyearth Posted July 8, 2007 Author Share Posted July 8, 2007 Thanks Yesideez ... MUCH appreciated! Link to comment https://forums.phpfreaks.com/topic/58834-solved-include-help/#findComment-292576 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.