Jump to content

[SOLVED] Include Help


holyearth

Recommended Posts

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

<?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");
}
?>

;D

Link to comment
https://forums.phpfreaks.com/topic/58834-solved-include-help/#findComment-291885
Share on other sites

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

<?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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.