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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.