广告合作
  • 今日头条

    今日头条

  • 百度一下

    百度一下,你就知道

  • 新浪网

    新浪网 - 提供新闻线索,重大新闻爆料

  • 搜狐

    搜狐

  • 豆瓣

    豆瓣

  • 百度贴吧

    百度贴吧——全球领先的中文社区

  • 首页 尚未审核订阅工具 订阅

    随机生成防伪码及从数据库导出到excel表格

    来源:网络收集  点击:  时间:2024-02-10
    【导读】:
    随机生成防伪码及从数据库导出到excel表格方法/步骤

    一、创建数据库

    随便你命名数据库名称,我这里的是key,里面也这样一个表security_code,并且表里面有id,time,pici,skey这几个字段。

    二、编写需要的代码,并放在你的web环境下

    我这里编写了2个php文件,test.php、excel.php

    test.php(是访问页面操作的文件)

    ?php

    header(Content-Type:text/html; charset=utf-8);

    mysql_connect(localhost,root,root);

    mysql_select_db(Key);

    mysql_query(set names utf8);

    function createRandomStr($length){

    $str = array_merge(range(0,9),range(a,z),range(A,Z));

    shuffle($str);

    $str = implode(,array_slice($str,0,$length));

    return $str;

    }

    if(isset($_POST)){

    $pici=$_POST;

    $sl=$_POST;

    $sql=select skey from Security_code;

    $res=mysql_query($sql);

    for($j=0;$j$sl;$j++){

    $str=createRandomStr(18);

    for($i=0;$i$sl;$i++){

    $row=mysql_fetch_assoc($res);

    $str1=$row;

    if($str1==$str){

    break 2;

    }else{

    $datetime=date(Y-m-d H:i:s);

    $sql=insert into Security_code(time,skey,pici) values($datetime,$str,$pici);

    mysql_query($sql);

    ini_set(max_execution_time, 300);

    break 1;

    }

    }

    }

    }

    ?

    !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd

    html xmlns=http://www.w3.org/1999/xhtml

    head

    meta http-equiv=Content-Type content=text/html; charset=utf-8 /

    title生成防伪码/title

    /head

    body

    form action=?php echo $_SERVER ? method=post

    table style=width:600px;

    tr

    th批次:/th

    tdinput name=pc type=text/td

    /tr

    tr

    th数量: /th

    tdinput type=text name=sl //td

    /tr

    tr

    thnbsp;/th

    td

    input value= 生成防伪码 name=submit type=submit onclick=return confirm(确定要生成防伪码吗?)

    /td

    /tr

    /table

    /form

    form action=excel.php method=POST

    要导出的批次:input type=text name=pici/br/

    input type=submit name=submit value=Submit onclick=return confirm(确定要导出防伪码吗?) /

    /form

    /body

    /html

    excel.php(是从数据库导入excel文档的文件)

    ?php

    header(Content-Type:text/html; charset=utf-8);

    Header( Content-type: application/octet-stream );

    Header( Accept-Ranges: bytes );

    Header( Content-type:application/vnd.ms-excel );

    Header( Content-Disposition:attachment;filename=test.xls );

    $con = mysql_connect(localhost,root,root);

    mysql_select_db(key);

    mysql_query(set names utf8);

    if(isset($_POST)){

    $pici=$_POST;

    $sql = select id,time,pici,skey from security_code where pici=$pici;

    }

    $result = mysql_query($sql,$con);

    echo id\ttime\tpici\tskey;

    while ($rs=mysql_fetch_array($result)){

    echo \n;

    echo $rs.\t.$rs.\t.$rs.\t.$rs;

    }

    ?

    三、测试

    1、首先从你的web服务器上访问test.php文件,然后输入生成防伪码的批次和数量,再点击生成防伪码,如图

    2、输入要导出的批次,点击导出,再确定下载,如图

    3、打开下载的excel文档,里面的就是按批次随机生成的防伪码。

    EXCEL数据库
    本文关键词:

    版权声明:

    1、本文系转载,版权归原作者所有,旨在传递信息,不代表看本站的观点和立场。

    2、本站仅提供信息发布平台,不承担相关法律责任。

    3、若侵犯您的版权或隐私,请联系本站管理员删除。

    4、文章链接:http://www.1haoku.cn/art_20949.html

    相关资讯

    ©2019-2020 http://www.1haoku.cn/ 国ICP备20009186号05-06 09:30:04  耗时:0.030
    0.0303s