PHP implements active number of clicks and "water injection" machines

Source: Internet
Author: User
Today, I accidentally saw a website whose counters can be updated on static pages. I think it should be done by using js. when I open the source code, I can see that: <divalign = center> <SPANclass = Article_tdbgall> Author: Unknown article origins:

Today, I accidentally saw a website whose counters can be updated on static pages. I think it should be done by using js. when I open the source code, I can see that:

<Div align = center> <SPAN class = Article_tdbgall>
Author: Unknown article Origin: Meidi. Net
Clicks:
<Script language = 'javascript 'src = '/Article/GetHits. asp? ArticleID = 759 '> </script>
Updated on: 2005-5-27 </SPAN>
</Div>

The number of clicks is followed by an asp file for processing, so I will open this file to see:

Document. write ('20140901 ');

Right, that is, the number of output results after the GetHists. asp file processes the ArticleID and then extracts the result: document. write ('Times'), and then the static page can be directly referenced.

After all, the bad guys are the bad guys, so I thought, how can we be agile to promote clicks? Manual refresh is not very similar. well, write a PHP program to actively visit this file.

The PHP code is as follows:

<? Php
/* Access_url.php */
Define (SUM, 1000); // number of visits
Define (L_TIME, 1000); // time when the script is forced to be executed
Define (S_TIME, 1); // The sleep time between each visit
$ Url = http: // www. ***. com/Article/GetHits. asp? ArticleID = 759; // address to be visited
Set_time_limit (L_TIME );

// Visit the specified URL function
Function access_url ($ url)
{
If ($ url = '') return false;
$ Fp = fopen ($ url, 'r') or exit ('open url faild! ');
If ($ fp ){
While (! Feof ($ fp )){
$ File = fgets ($ fp );
Echo $ file. '\ n <p> </p> \ n ';
}
Unset ($ file );
}
}

// Perform the test
For ($ I = 0; $ I <SUM; $ I ){
Access_url ($ url );
Sleep (S_TIME );
}
?>

If you run the above program, you will continue to visit the specified URL address. Naturally, the number of visits will continue to increase, resulting in the effect of water injection. If the traffic is high and multiple programs are used for running, it is easy to cause denial of service (DoS. If the other party's defense measures are used to correct the code and submit the code for the forum, the consequences of Forum injection can be easily realized.

Defense methods:

1. the Session mechanism is applied in the code. when the user submits a Session ID, the user determines whether the content has been submitted. if the Session ID has been submitted, the user will not be able to click it.

2. after the user submits the record, the user's IP address will not be submitted if it is submitted again within the specified time.

3. after the user submits the content, write the content into the Cookie on the user client. if the user submits the content again, check whether the client has a Cookie to determine whether the request is committed.

There are many other ways to search, or use your imagination to do better.

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.