-3

"Notice: Undefined index: size in C:\Nginx\html\default.php on line 3"

I'm getting this error whenever I try opening my new game website. Does someone here have any ideas on how to fix this?

<?php
$size = $_GET["size"];

/** Default dimensions **/
$width = "960";
$height = "550";

/** Show **/
switch($size) {
    default:
        break;
    case 'large':
        $width = "1185";
        $height = "679";
        break;
    case 'huge':
        $width = "1792";
        $height = "1027";
        break;
    case 'tiny':
        $width = "706";
        $height = "405";
        break;
}
?>
Charles
  • 50,943
  • 13
  • 104
  • 142
  • dupe of many many questions. also, it's a PHP notice, not an error. There is a significant difference – James Aug 26 '13 at 01:07
  • 1
    After you fix that error as answered by vollie, be sure to move the default case to the end of the switch. PHP evaluates them in order so when at the top, the default will always apply. – bitfiddler Aug 26 '13 at 01:07

1 Answers1

1

Yes, you don't have size set in your request; thus, the index 'size' in variable $_GET is not set (i.e. undefined). If you request like so default.php?size=large it should be gone (if you don't do anything to unset it elsewhere).

Additionally you really should check whether it's set or not with somehting like:

$size = isset($_GET["size"]) ? $_GET["size"] : 'normal';

which will check if size=something is in your query and if it's not will default to 'normal'.

vollie
  • 1,005
  • 1
  • 11
  • 20