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.

$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
/*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($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($upperlimitmonth<$datecomponentmonth){ $var=bad-date;}
          if($upperlimitmonth==$datecomponentsmonth){ if($upperlimitday<$datecomponentsday){ $var=bad-date; }}

header('Content-Type: image/gif');
4 Years
Discussion Span
Last Post by broj1

Your code contains several statements of this form


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') {


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

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.


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.