PHP verification code @ symbol

Source: Internet
Author: User
Tags imagejpeg
PHP verification code @ symbol PHPcode & lt ;? Phpsession_start (); for ($ i0; $ I & lt; 4; $ I ++) {@ $ rand. dechex (rand (); if the @ symbol is not added, the image cannot be displayed .} @ $ _ SESSION [check_p help PHP verification code @ symbol
PHP code
  
  



PHP code
  
  


If I do not add the @ symbol, an error is returned. The following is an error message.
Notice: Use of undefined constant code-assumed 'code' in F: \ wamp \ apps \ project \ code_sub.php on line 3

Notice: Use of undefined constant code-assumed 'code' in F: \ wamp \ apps \ project \ code_sub.php on line 4

Notice: Use of undefined constant check_pic-assumed 'check _ pic 'in F: \ wamp \ apps \ project \ code_sub.php on line 4

After adding the @ symbol, everything will be normal. what is the error?


------ Solution --------------------
Quote $ _ SESSION ["check_pic"]

Undefined constant refers to an undefined constant, which is treated as a constant without quotation marks.
------ Solution --------------------
PHP code
For ($ I = 0; $ I <4; $ I ++) {$ rand = ''; $ rand. = dechex (rand (); // if the @ symbol is not added, the image cannot be displayed. } $ _ SESSION ['Check _ pic '] = $ rand; // if the @ symbol in front of it is removed, an error is returned and it is garbled.
------ Solution --------------------
$ Rand. =

This variable is used when no value is assigned, so the notice error occurs. The image is binary and the notice is text. The combination of the two causes the image to fail to be displayed.

Solution:
Assign a value to $ rand first.

$ Rand = '';


------ Solution --------------------
PHP code
Session_start (); $ rand = ''; for ($ I = 0; $ I <4; $ I ++) {$ rand. = dechex (rand (); // if the @ symbol is not added, the image cannot be displayed. } $ _ SESSION ['Check _ pic '] = $ rand; // if the @ symbol in front of it is removed, an error is returned and it is garbled. $ Im = imagecreatetruecolor (255,255,255, 30); $ bg = imagecolorallocate ($ im, 0); $ te = imagecolorallocate ($ im,); imagestring ($ im, 0, $ rand, $ te); header ("content-type: image/jpeg"); imagejpeg ($ im );
------ Solution --------------------
Discussion
PHP code

Session_start ();

For ($ I = 0; $ I <4; $ I ++ ){
@ $ Rand. = dechex (rand (); // if the @ symbol is not added, the image cannot be displayed.
}
@ $ _ SESSION [check_pic] = $ rand; // if the @ symbol in front is removed, an error is returned and all characters are garbled. ......

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.