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. ......