javascript - Through the session, the verification code generated by php can be refreshed by clicking on it. Why?
PHP中文网
PHP中文网 2017-05-16 12:59:41
0
3
448

Generate verification code through php, and then output it with img tag.

Excuse me, if there is session_start(), why is the onclick event written like this, and clicking will have the effect of refreshing the verification code? (A new verification code will appear)
There is no session, and the click is invalid.

html code

<img src="verifyCode.php" onclick="this.src='verifyCode.php'"/>

php

//省略验证码生成代码...

imagepng($image);//输出图片

session_start();//开始会话
PHP中文网
PHP中文网

认证0级讲师

reply all(3)
某草草

onclick="this.src='verifyCode.php?id='+Math_random()"/>
This should be enough. Add a random number to the image, it will be different every time and you can refresh it

曾经蜡笔没有小新

Is this code session_start() before the image is created?
If it was before, generally when making the canvas, you need to inject verification information into $_SESSION. The injection may fail because the session is not opened, and the production of verification code images will be terminated.

给我你的怀抱

Use session to verify the graphic verification code. The general principle is to first store the current verification code a in the session, then use a to generate the graphic verification code and return it to the client. The client inputs the verification code a to the server, and the server verifies it based on the data stored in the current session.

If you use this method and the session is not enabled, you will not be able to store and replace the verification code a in the session, and of course an error will occur.
(Note: The output of the image has nothing to do with the activation of the session)

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template