When PHP creates a verification code, what is the role of a parameter?

Source: Internet
Author: User
When PHP creates a verification code, what is the role of a parameter? PHP verification code $ _ POST []


For ($ I = 0; $ I <$ num; $ I ++) {$ x = rand (1, 8) + $ imagewidth * $ I/4; $ y = rand (1, $ imageheight/4); $ font = ImageColorAllocate ($ im, rand (100,255), rand (0,100), rand (100,255 )); // Generate random color $ authnum = rand (); $ vcodes. = $ authnum; imagestring ($ im, 15, $ x, $ y, $ authnum, $ font );}

In this loop statement, what is the function of $ num?

This is because the imagestring () function adds numbers to the image. I think $ num is definitely used to limit the number of numbers added to the image,
However, if you change $ num = 4, $ num = 15, or another number, the image is still 4 characters long.

I also want to ask, if it is weak, the parameters passed through post and get, such as login? Id = 2 & value = 3, this id, value through
After $ _ POST or $ _ GET is obtained, the values of id and value are integers or characters!

I don't want to verify it. it's too much trouble. thank you !!!


Reply to discussion (solution)

The first question: do you want to use $ num = 2 to try it or use four numbers?
The calculation method of $ x can only display four numbers.

The second question is not clear whether it is a character or an integer, but it can be used as a character or an integer. this is the charm of PHP.

First, see upstairs.

Second string

You have fixed the image width and height...

Take a look at me again:
The first question: do you want to use $ num = 2 to try it or use four numbers?
The calculation method of $ x can only display four numbers.

The second question is not clear whether it is a character or an integer, but it can be used as a character or an integer. this is the charm of PHP.
After modifying $ num <4, it does change, but can you give me the specific limit of $ x?

$ X = rand (1, 8) + $ imagewidth * $ I/4;
Adjust the writing order.
$ X = $ imagewidth/4 * $ I + rand (1, 8 );
Where:
$ Imagewidth/4 Divide the canvas width into 4 points
$ Imagewidth/4 * $ I starting position of the $ I character on the canvas
Rand () let the starting position be shifted to several points

When the number of characters exceeds 4, there is no limit, but the calculated position is outside the canvas. Painted and White

$ X = rand (1, 8) + $ imagewidth * $ I/4;
Adjust the writing order.
$ X = $ imagewidth/4 * $ I + rand (1, 8 );
Where:
$ Imagewidth/4 Divide the canvas width into 4 points
$ Imagewidth/4 * $ I starting position of the $ I character on the canvas
Rand () let the starting position be shifted to several points

When the number of characters exceeds 4, there is no limit, but the calculated position is outside the canvas. Painted and White

I seem to have understood it a bit. if I want to make the generated random code contain letters and numbers, how should I rewrite it?
Hope you can give me some advice


$ X = rand (1, 8) + $ imagewidth * $ I/4;
Adjust the writing order.
$ X = $ imagewidth/4 * $ I + rand (1, 8 );
Where:
$ Imagewidth/4 Divide the canvas width into 4 points
$ Imagewidth/4 * $ I starting position of the $ I character on the canvas
Rand () let the starting position be shifted to several points

When the number of characters exceeds 4, there is no limit, but the calculated position is outside the canvas. Painted and White

I seem to have understood it a bit. if I want to make the generated random code contain letters and numbers, how should I rewrite it?
Hope you can give me some advice

To be honest, if you have understood the above, you only need to take a look at several parameters of imagestring to understand this problem.

The fifth parameter of imagestring () is to specify what to write.

$ Str = "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ ";
Then it's okay to randomly retrieve a word from it each time?

$ Str = "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ"; for ($ I = 0; $ I <$ num; $ I ++) {$ x = rand) + $ imagewidth * $ I/4; $ y = rand (1, $ imageheight/4); $ font = ImageColorAllocate ($ im, rand (100,255), rand (0,100 ), rand (100,255); // Generate random color $ authnum = substr ($ str, rand (), 1 ); // select a random $ vcodes from 10 + 26 letters. = $ authnum; imagestring ($ im, 15, $ x, $ y, $ authnum, $ font );}

The first question: do you want to use $ num = 2 to try it or use four numbers?
The calculation method of $ x can only display four numbers.

The second question is not clear whether it is a character or an integer, but it can be used as a character or an integer. this is the charm of PHP.

Thank you only for your appreciation... , Score now !!

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.