How to implement a daily vote for each ip address in php _ PHP Tutorial

Source: Internet
Author: User
Php implements a daily vote for each ip address. The following is the implementation code :? Php *** PHP + MySQL ** CREATETABLEIFNOTEXISTS 'IP _ poll '(* 'IP' varchar (15) NOTNULL, * 'date' datetimeNOTNULL *) enginemyisamdefacharcharset the following code is implemented:

  1. /**
  2. * PHP + MySQL
  3. * Create table if not exists 'IP _ poll '(
  4. * 'IP' varchar (15) not null,
  5. * 'Date' datetime NOT NULL
  6. *) ENGINE = MyISAM default charset = latin1;
  7. *
  8. */
  9. Function getIP (){
  10. $ Ip = "";
  11. If (getenv ("HTTP_CLIENT_IP") $ ip = getenv ("HTTP_CLIENT_IP ");
  12. Else if (getenv ("HTTP_X_FORWARDED_FOR") $ ip = getenv ("HTTP_X_FORWARDED_FOR ");
  13. Else if (getenv ("REMOTE_ADDR") $ ip = getenv ("REMOTE_ADDR ");
  14. Else $ ip = "";
  15. Return $ ip;
  16. }
  17. Function checkVote ()
  18. {
  19. $ Ip = getIP ();
  20. $ SQL = "select count (*) from ip_poll where ip = '". $ ip. "'and SUBSTR (date,) = '". date ("Y-m-d "). "'";
  21. If ($ res = mysql_query ($ SQL ))
  22. {
  23. $ Row = mysql_num_rows ($ res );
  24. If ($ row = 0)
  25. {
  26. $ Sqloud = "insert into ip_poll values ('". $ ip. "', now ());";
  27. If (mysql_query ($ sqlIns ))
  28. Return true;
  29. Else
  30. Return false;
  31. } Else {
  32. Return false;
  33. }
  34. } Else {
  35. Return false;
  36. }
  37. }
  38. ?>

Why :? Php/*** PHP + MySQL * create table if not exists 'IP _ poll '(* 'IP' varchar (15) not null, * 'date' datetime not null *) ENGINE = MyISAM default charset =...

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.