Does the include function work when the php file name and class name are the same?

Source: Internet
Author: User
File name: it turns out to be ValidationCode. modify php to validate. the verification code can be displayed normally after php, and the code is requested in the browser. show the verification code {code...} in the PHP file ...} code. php {code ...} file name: it turns out to be ValidationCode. php
After being changed to validate. php, the verification code is displayed normally,
The verification code is displayed in the request code. php file in the browser.


  width = $width;            $this->height = $height;            $this->num_chars = $num_chars;        }                function showImage(){            $this->createImage();            $this->drawBorder();            $this->drawChars();            $this->outPic();        }                //create canvas         function createImage(){            $this->image = imagecreate($this->width,$this->height);            //$rand_color = imagecolorallocate($this->image,rand(0,255),rand(0,255),rand(0,255));            $back = imagecolorallocate($this->image,0,0,0);            $border = imagecolorallocate($this->image,255,255,255);            imagefill($this->image,0,0,$back);            //imagefilledrectangle($thid->image,self::BORDER,self::BORDER,$this->width-self::BORDER,$this->height-self::BORDER,$border);            //imageline($this->image,1,1,100,100,$rand_color);            //$this->outPic();        }        //draw border        private function drawBorder(){            $outer_bg_color = imagecolorallocate($this->image,0,0,0);            $inner_bg_color = imagecolorallocate($this->image,255,255,255);            imagefill($this->image,0,0,$outer_bg_color);            imagefilledrectangle($this->image,self::BORDER,self::BORDER,$this->width-self::BORDER-1,$this->height-self::BORDER-1,$inner_bg_color);        }                    //create char content          function createChar(){            $rand_ascii="";            $rand_type = rand(0,2);            switch($rand_type){                case 0:                    $rand_ascii = rand(48,57);                     break;                case 1:                     $rand_ascii = rand(65,90);                   break;                case 2:                     $rand_ascii = rand(97,122);                   break;            }            $rand_str = sprintf("%c",$rand_ascii);            return $rand_str;        }                    //draw char         private function drawChars(){            $x = $this->width/$this->num_chars+1;            $y = $this->height/2;            for($index = 0; $index<$this->num_chars; $index++){                $rand_color = imagecolorallocate($this->image,rand(0,255),rand(0,255),rand(0,255));                imagechar($this->image,3,$x*$index+2,$y-$y/2,$this->createChar(),$rand_color);            }        }        //out pic        private function outPic(){            header("content-type:image/png");            imagepng($this->image);        }                 function __destruct(){             imagedestroy($this->image);         }    }        /*$code = new ValidationCode();    //echo $code->createChar();    $code->showImage();*/?>

Code. php


  createChar();    $code->showImage();  ?>

The problem has been closed. cause: you have found the cause of the problem.

Reply content:

File name: Originally ValidationCode. php
After being changed to validate. php, the verification code is displayed normally,
The verification code is displayed in the request code. php file in the browser.


  width = $width;            $this->height = $height;            $this->num_chars = $num_chars;        }                function showImage(){            $this->createImage();            $this->drawBorder();            $this->drawChars();            $this->outPic();        }                //create canvas         function createImage(){            $this->image = imagecreate($this->width,$this->height);            //$rand_color = imagecolorallocate($this->image,rand(0,255),rand(0,255),rand(0,255));            $back = imagecolorallocate($this->image,0,0,0);            $border = imagecolorallocate($this->image,255,255,255);            imagefill($this->image,0,0,$back);            //imagefilledrectangle($thid->image,self::BORDER,self::BORDER,$this->width-self::BORDER,$this->height-self::BORDER,$border);            //imageline($this->image,1,1,100,100,$rand_color);            //$this->outPic();        }        //draw border        private function drawBorder(){            $outer_bg_color = imagecolorallocate($this->image,0,0,0);            $inner_bg_color = imagecolorallocate($this->image,255,255,255);            imagefill($this->image,0,0,$outer_bg_color);            imagefilledrectangle($this->image,self::BORDER,self::BORDER,$this->width-self::BORDER-1,$this->height-self::BORDER-1,$inner_bg_color);        }                    //create char content          function createChar(){            $rand_ascii="";            $rand_type = rand(0,2);            switch($rand_type){                case 0:                    $rand_ascii = rand(48,57);                     break;                case 1:                     $rand_ascii = rand(65,90);                   break;                case 2:                     $rand_ascii = rand(97,122);                   break;            }            $rand_str = sprintf("%c",$rand_ascii);            return $rand_str;        }                    //draw char         private function drawChars(){            $x = $this->width/$this->num_chars+1;            $y = $this->height/2;            for($index = 0; $index<$this->num_chars; $index++){                $rand_color = imagecolorallocate($this->image,rand(0,255),rand(0,255),rand(0,255));                imagechar($this->image,3,$x*$index+2,$y-$y/2,$this->createChar(),$rand_color);            }        }        //out pic        private function outPic(){            header("content-type:image/png");            imagepng($this->image);        }                 function __destruct(){             imagedestroy($this->image);         }    }        /*$code = new ValidationCode();    //echo $code->createChar();    $code->showImage();*/?>

Code. php


  createChar();    $code->showImage();  ?>

Test: Entry Code


  createChar();$code->showImage();

File name:

Test results:

Conclusion: the file name is irrelevant to the class name during the include operation. The result is acceptable. I don't know why you can't. But I tested it.

It's really fake! The file name does not work like the class name. it's amazing! Are there any error messages?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.