php实现每个ip每天投票一次的方法_PHP教程

WBOY
Release: 2016-07-21 14:53:40
Original
908 people have browsed it

 下面是实现的代码:

  1.  
  2. /**
  3.  * PHP+MySQL
  4.  * CREATE TABLE IF NOT EXISTS `ip_poll` (
  5.  * `ip` varchar(15) NOT NULL,
  6.  * `date` datetime NOT NULL
  7.  * ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
  8.  *
  9.  */
  10.  
  11. function getIP() {
  12. $ip=”";
  13. if (getenv(“HTTP_CLIENT_IP”)) $ip = getenv(“HTTP_CLIENT_IP”);
  14. else if(getenv(“HTTP_X_FORWARDED_FOR”)) $ip = getenv(“HTTP_X_FORWARDED_FOR”);
  15. else if(getenv(“REMOTE_ADDR”)) $ip = getenv(“REMOTE_ADDR”);
  16. else $ip = “”;
  17. return $ip;
  18. }
  19.  
  20. function checkVote()
  21. {
  22. $ip= getIP();
  23. $sql= “select count(*) from ip_poll where ip = ‘”.$ip.”‘ and SUBSTR(date,1,10) = ‘”.date(“Y-m-d”).”‘”;
  24. if($res= mysql_query($sql))
  25. {
  26. $row= mysql_num_rows($res);
  27. if($row == 0)
  28. {
  29. $sqlIns= “insert into ip_poll values (‘”.$ip.”‘,now());”;
  30. if(mysql_query($sqlIns))
  31. return true;
  32. else
  33. return false;
  34. }else{
  35. return false;
  36. }
  37. }else{
  38. return false;
  39. }
  40. }
  41.  
  42. ?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/371356.htmlTechArticle下面是实现的代码: ?php /** * PHP+MySQL * CREATE TABLE IF NOT EXISTS `ip_poll` ( * `ip` varchar(15) NOT NULL, * `date` datetime NOT NULL * ) ENGINE=MyISAM DEFAULT CHARSET=...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!