PHP obtains IP file write and row Modification

Source: Internet
Author: User
· I made a vote and put it on the subscription number. I used cookies to prohibit ticket refresh. This is really only a matter of preventing the gentleman from defending against the villain and malicious votes. So I finally used IP addresses to restrict it; because it is a short activity, the IP record is written to the file and no longer written into the table. My validation rule is: within 3 minutes

· I made a vote and put it on the subscription number. I used cookies to prohibit ticket refresh. This is really only a matter of preventing the gentleman from defending against the villain and malicious votes. So I finally used IP addresses to restrict it; because it is a short activity, the IP record is written to the file and no longer written into the table. My validation rule is: within 3 minutes

· I made a vote and put it on the subscription number. I used cookies to prohibit ticket refresh. This is really only a matter of preventing the gentleman from defending against the villain and malicious votes. So I finally used IP addresses to restrict it;

Because it is a short activity, the IP address record is written into the file and no more data is written into the table;

My verification rule is: only one vote can be cast for the same IPaddress corresponding to the same ID within 3 minutes;

The code is not well written. I am in a hurry to hand in the Code. Let's look at it first and then improve it later.

Function GetIP () {if ($ _ SERVER ["HTTP_X_FORWARDED_FOR"]) $ ip = $ _ SERVER ["HTTP_X_FORWARDED_FOR"]; else if ($ _ SERVER ["HTTP_CLIENT_IP"]) $ ip = $ _ SERVER ["HTTP_CLIENT_IP"]; else if ($ _ SERVER ["REMOTE_ADDR"]) $ ip = $ _ SERVER ["REMOTE_ADDR"]; else if (getenv ("token") $ ip = getenv ("HTTP_X_FORWARDED_FOR"); else if (getenv ("HTTP_CLIENT_IP") $ ip = getenv ("HTTP_CLIENT_IP "); else if (getenv ("REMOT E_ADDR ") $ ip = getenv (" REMOTE_ADDR "); else $ ip =" Unknown "; return $ ip ;}$ iptxt = fopen (". /data/lovewall.txt "," a + "); $ ip = GetIP (); $ ifok = $ I = 1; while (! Feof ($ iptxt) {$ now = fgets ($ iptxt); // obtain the content of the traversal line if (! Empty ($ now) {$ now_arr = explode ('#', $ now ); if ($ now_arr [1] ===$ ip & $ now_arr [2] === _ G ['gp _ show ']. "\ n") {$ ifok = 0; if ($ now_arr ['0'] + 180> time () {$ return = array ('status' => 0, 'err _ msg '=>' a love letter can only be given once in three minutes '); echo json_encode ($ return); exit;} else {$ all = file_get_contents ('. /data/lovewall.txt '); $ new = time (). '#'. $ ip. '#'. $ _ G ['gp _ show ']. "\ n"; $ update_str = str_replace ($ now, $ new, $ all); // replace to indirectly modify file_put_contents ('. /data/lovewall.txt ', $ update_str) ;}}$ I ++;} if ($ ifok) {$ now = time (). "#". $ ip. "#". $ _ G ['gp _ show ']; fwrite ($ iptxt, $ now. "\ n");} fclose ($ iptxt );

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.