首页 > 编程技术 > php

php防止重复刷票原理分析

发布时间:2016-11-25 15:25

一开始是用验证码,别人就手动刷票,甚至网站花几百块买个验证码识别程序
限制ip地址,拔插网线就换了ip了,淘宝2块钱就可以买个ip自动变换器,自动重新拨号上网
cookies?清理也下就行了
session?页面关了就断了
mac地址?在设备管理器可以改
用户硬盘系列号?用软件能欺骗
注册用户才能投?除非你有很多注册用户
防不胜防。。。

建议 ip+验证码+session

验证码可以搞些有趣的


网友二

以下是我在一投票网站用到的防刷票方法,但是还是被疯狂刷

验证码 (不知道他刷票机怎么突破这一关的)
session验证(也不知道)
生成随机号
IP验证 (可以伪装)
投票来源 (可以伪装)

验证码弄个中文的,或是随机数字,让做计算,等等,这样应可以防住机器了,机器防不住那就是你代码有问题了

最后总结:

刷票问题一直都存在,只可能尽量减少刷票的方式,你要真的做到不让别人刷是不可能的,就算是加上注册,人家也可以注册n个号!你想想就算是真实的投票也一样会有拉投票的。要想做到不让别人刷票,只有你控制投票的人群!

这是我之前写的一段form代码

<form name="form1"  method="post" action="">
  <table width="200" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td><label>
        <input type="text" name="a1" />
      </label></td>
      <td><input type="text" name="a2" /></td>
      <td><input type="text" name="a3" /></td>
    </tr>
    <tr>
      <td><input type="text" name="a1" /></td>
      <td><input type="text" name="a2" /></td>
      <td><input type="text" name="a3" /></td>
    </tr>
    <tr>
      <td><input type="text" name="a1" /></td>
      <td><input type="text" name="a2" /></td>
      <td><input type="text" name="a3" /></td>
    </tr>
  </table><input name="" type="submit" value="提交" />
</form>
<?php教程
print_r($a1);
?>


原想是可以一次获取多但是行不通,通过网上找到了解决方法


所有需要传多个值input的name中加上[]
<td><input type="text" name="a1[]" /></td>

则php端读到的就是数组  var_dump($_POST['a1'])

 

  为了数据安全,防止注入需要过滤$_GET获得的字符串,一开始我还自已写过滤的函数,后

来看到php教程自带的一个过滤函数,所以把addslashes推荐给大家。
  一个使用 addslashes() 的例子是当你要往数据库教程中输入数据时。例如,将名字 O'reilly

插入到数据库中,这就需要对其进行转义。大多数据库使用 作为转义符:O'reilly。这

样可以将数据放入数据库中,而不会插入额外的 。当 PHP 指令 magic_quotes_sybase 被

设置成 on 时,意味着插入 ' 时将使用 ' 进行转义。
  例子:

 

mysql教程和php自带很多函数可以处理字符问题,下面给出几个会经常用到的.
ps教程:由于php6开始不支持magic_quotes_gpc,所以下面的东西都是假设在

magic_quotes_gpc=off的条件上(不知道php6会出什么新东西....)

mysql_real_escape_string()
定义:函数转义 SQL 语句中使用的字符串中的特殊字符。
语法: mysql_real_escape_string(string,connection)
说明:本函数将 string 中的特殊字符转义,并考虑到连接的当前字符集,因此可以安全用于

mysql_query()。
由于实例代码过长,给出函数解释链接


本函数将 string 中的特殊字符转义,并考虑到连接的当前字符集,因此可以安全用于

mysql_query()。
数据库攻击。本例演示如果我们不对用户名和密码应用 mysql_real_escape_string() 函数

会发生什么:

<?php
$con = mysql_connect("localhost", "hello", "321");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

$sql = "SELECT * FROM users
WHERE user='{$_POST['user']}'
AND password='{$_POST['pwd']}'";
mysql_query($sql);

// 不检查用户名和密码
// 可以是用户输入的任何内容,比如:
$_POST['user'] = 'john';
$_POST['pwd'] = "' OR ''='";

// 一些代码...

mysql_close($con);
?>那么 SQL 查询会成为这样:

SELECT * FROM users
WHERE user='john' AND password='' OR ''=''这意味着任何用户无需输入合法的密码即可

登陆


addSlashes()
定义:addslashes() 函数在指定的预定义字符前添加反斜杠。
语法:addslashes(string)
注释:默认情况下,PHP 指令 magic_quotes_gpc 为 on,对所有的 GET、POST 和 COOKIE

数据自动运行 addslashes()。不要对已经被 magic_quotes_gpc 转义过的字符串使用

addslashes(),因为这样会导致双层转义。遇到这种情况时可以使用函数

get_magic_quotes_gpc() 进行检测。
由于实例代码过长,给出函数解释链接
相关函数

 

<?php
   $str = "Is your name O'reilly?";

   // 输出:Is your name O'reilly?
   echo addslashes($str);
  ?>

StripSlashes()去掉反斜线字符
 
stripslashes() 函数删除由 addslashes() 函数添加的反斜杠。

语法
stripslashes(string)

<?php
echo stripslashes("Who's John Adams?");
?>

PHP 的 HTTP 认证机制仅在 PHP 以 Apache 模块方式运行时才有效,因此该功能不适用于 CGI 版本。在 Apache 模块的 PHP 脚本中,可以用 header() 函数来向客户端浏览器发送“Authentication Required”信息,使其弹出一个用户名/密码输入窗口。当用户输入用户名和密码后,包含有 URL 的 PHP 脚本将会再次和预定义变量 PHP_AUTH_USER、PHP_AUTH_PW 和 AUTH_TYPE 一起被调用,这三个变量分别被设定为用户名,密码和认证类型。预定义变量保存在 $_SERVER 或者 $HTTP_SERVER_VARS 数组中。系统仅支持“基本的”认证

<?php教程
   $authorized = FALSE;

   if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) {
      $authFile = file("./password.txt");

      foreach ($authFile as $login) {
         list($username, $password) = explode(":", $login);
         $password = trim($password);
         if (($username == $_SERVER['PHP_AUTH_USER']) && ($password == md5($_SERVER['PHP_AUTH_PW']))) {
            $authorized = TRUE;
            break;
         }
      }
   }

   // If not authorized, display authentication prompt or 401 error
   if (! $authorized) {
      header('WWW-Authenticate: Basic Realm="Secret Stash"');
      header('HTTP/1.0 401 Unauthorized');
      print('You must provide the proper credentials!');
      exit;
   }

?>


<!-- password.txt
joe:60d99e58d66a5e0f4f89ec3ddd1d9a80

-->


import os
import sys
import re
import time
def listdir(dirs,liston='0'):
flog = open(os.getcwd()+"/check_php教程_shell.log","a+")
if not os.path.isdir(dirs):
print "directory %s is not exist"% (dirs)
return
lists = os.listdir(dirs)
for list in lists:
filepath = os.path.join(dirs,list)
if os.path.isdir(filepath):
if liston == '1':
listdir(filepath,'1')
elif os.path.isfile(filepath):
filename = os.path.basename(filepath)
if re.search(r".(?:php|inc|html?)$", filename, re.ignorecase):
i = 0
iname = 0
f = open(filepath)
while f:
file_contents = f.readline()
if not file_contents:
break
i += 1
match = re.search(r'''(?p<function>b(?:include|require)(?:_once)?b)s*(?s*["'](?p<filename>[^;]*(?<!.(?:php|inc)))["'])?s*;''', file_contents, re.ignorecase| re.multiline)
if match:
function = match.group("function")
filename = match.group("filename")
if iname == 0:
info = 'n[%s] :n'% (filepath)
else:
info = ''
info += 't|-- [%s] - [%s] line [%d] n'% (function,filename,i)
flog.write(info)
print info
iname += 1
match = re.search(r'b(?p<function>eval|proc_open|popen|shell_exec|exec|passthru|system|assert|fwrite|create_function)bs*(', file_contents, re.ignorecase| re.multiline)
if match:
function = match.group("function")
if iname == 0:
info = 'n[%s] :n'% (filepath)
else:
info = ''
info += 't|-- [%s] line [%d] n'% (function,i)
flog.write(info)
print info
iname += 1
match = re.search(r'(^|(?<=;))s*`(?p<shell>[^`]+)`s*;', file_contents, re.ignorecase)
if match:
shell = match.group("shell")
if iname == 0:
info = 'n[%s] :n'% (filepath)
else:
info = ''
info += 't|-- [``] command is [%s] in line [%d] n'% (shell,i)
flog.write(info)
print info
iname += 1
match = re.search(r'(?p<shell>$_(?:pos|ge|reques)t)s*[[^]]+]s*(', file_contents, re.ignorecase)
if match:
shell = match.group("shell")
if iname == 0:
info = 'n[%s] :n'% (filepath)
else:
info = ''
info += 't|-- [``] command is [%s] in line [%d] n'% (shell,i)
flog.write(info)
print info
iname += 1
f.close()
flog.close()
if '__main__' == __name__:
argvnum = len(sys.argv)
liston = '0'
if argvnum == 1:
action = os.path.basename(sys.argv[0])
print "command is like:n %s d:wwwroot n %s d:wwwroot 1 -- recurse subfolders"% (action,action)
quit()
elif argvnum == 2:
path = os.path.realpath(sys.argv[1])
listdir(path,liston)
else:
liston = sys.argv[2]
path = os.path.realpath(sys.argv[1])
listdir(path,liston)
flog = open(os.getcwd()+"/check_php_shell.log","a+")
isotimeformat='%y-%m-%d %x'
now_time = time.strftime(isotimeformat,time.localtime())
flog.write("n----------------------%s checked ---------------------n"% (now_time))
flog.close()
标签:[!--infotagslink--]

您可能感兴趣的文章: