0

The following script is supposed to take in a date formated YYYY-MM-DD and output an image. It is also designed to display an error image if the date inputed is before the start date defined in the script or after the current date. The problem is that it doesn't seem to be outputting anything so I'm posting to see if anyone notices a problem with it.

<?php
$var = $_GET['date'];
//get date components for the input date
$datecomponents = $var;
$datecomponentsyear = $datecomponents;
$datecomponentsmonth = $datecomponents;
$datecomponentsday = $datecomponents;
$datecomponentsyear = mb_substr($datecomponentsyear,0,4);
$datecomponentsmonth = mb_substr($datecomponentsmonth,5,2);
$datecomponentsday = mb_substr($datecomponentsday,8,2);
//get date components for today's date
$upperlimit = date(DATE_ATOM);
$upperlimit = mb_substr($datecomponentsyear,0,10);
$upperlimityear = $upperlimit;
$upperlimitmonth = $upperlimit;
$upperlimitday = $upperlimit;
$upperlimityear = mb_substr($upperlimityear,0,4);
$upperlimitmonth = mb_substr($upperlimitmonth,5,2);
$upperlimitday = mb_substr($upperlimitday,8,2);
//date components for date of first comic
$lowerlimityear=2012;
$lowerlimitmonth=09;
$lowerlimitday=01;
/*image security feature: prevents the display of a comic before the date of the first comic or after today's date. The script assumes that there is a comic with a correctly formatted date available for every day from the start date to the present date. */
if($lowerlimityear>$datecomponentsyear){ $var=bad-date;}
if($lowerlimityear==$datecomponentsyear){ 
          if($lowerlimitmonth>$datecomponentmonth){ $var=bad-date;}
          if($lowerlimitmonth==$datecomponentsmonth){ if($lowerlimitday>$datecomponentsday){ $var=bad-date; }}
 }
//Begin upper date verification
if($upperlimityear<$datecomponentsyear){ $var=bad-date; }
if($upperlimityear==$datecomponentsyear){ 
          if($upperlimitmonth<$datecomponentmonth){ $var=bad-date;}
          if($upperlimitmonth==$datecomponentsmonth){ if($upperlimitday<$datecomponentsday){ $var=bad-date; }}
 }

$imagepath="daily/$var.gif";
$image=imagecreatefromgif($imagepath);
header('Content-Type: image/gif');
imagejpeg($image);
?>
2
Contributors
4
Replies
5
Views
5 Years
Discussion Span
Last Post by broj1
0

Your code contains several statements of this form

$var=bad-date;

If you intended to assign a string 'bad-date' to $var enclose it with quotes.

Before displaying image you should then test the $var if it contains valid date:

if($var != 'bad-date') {

    $imagepath="daily/$var.gif";
    ...
}
2

An error could also be on line 13

$upperlimit = mb_substr($datecomponentsyear,0,10);

You should propbably use $upperlimit for calculating the upper limit:

$upperlimit = mb_substr($upperlimit,0,10);
Votes + Comments
Thanks!, this post and the one before it were very helpful
0

Thank You, your help combined with a few things I just noticed (I had misnamed some of the variables and lowerlimit needed to be a string) seems to have gotten the script working.

0

You are welcome. Just to remind you to mark the solved if there are no more questions.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.