PHP8.1.21版本已发布
vue8.1.21版本已发布
jquery8.1.21版本已发布

教你php如何实现验证码_php实例

原创
2016-06-07 17:09:38 644浏览

验证码在表单实现越来越多了,但是用js的写的验证码,总觉得不方便,所以学习了下php实现的验证码。好吧,其实是没有事情干,但是又不想浪费时间,所以学习了下php实现验证码。正所谓,技多不压身。而且,也可以封装成一个函数,以后使用的时候也是很方便的,当然现在未封装。

现在来说说简单的纯数字验证码吧。

如果是初学者,建议按照我代码的注释 //数字 一步步来。最简单的方法,还是把整个代码复制走了。

新建一个captcha.php:

php
  //10>设置session,必须处于脚本最顶部
  session_start();

  $image = imagecreatetruecolor(100, 30);    //1>设置验证码图片大小的函数
  //5>设置验证码颜色 imagecolorallocate(int im, int red, int green, int blue);
  $bgcolor = imagecolorallocate($image,255,255,255); //#ffffff
  //6>区域填充 int imagefill(int im, int x, int y, int col) (x,y) 所在的区域着色,col 表示欲涂上的颜色
  imagefill($image, 0, 0, $bgcolor);
  //10>设置变量
  $captcha_code = "";
  //7>生成随机数字
  for($i=0;$i<4;$i++){
    //设置字体大小
    $fontsize = 6;    
    //设置字体颜色,随机颜色
    $fontcolor = imagecolorallocate($image, rand(0,120),rand(0,120), rand(0,120));      //0-120深颜色
    //设置数字
    $fontcontent = rand(0,9);
    //10>.=连续定义变量
    $captcha_code .= $fontcontent;  
    //设置坐标
    $x = ($i*100/4)+rand(5,10);
    $y = rand(5,10);

    imagestring($image,$fontsize,$x,$y,$fontcontent,$fontcolor);
  }
  //10>存到session
  $_SESSION['authcode'] = $captcha_code;
  //8>增加干扰元素,设置雪花点
  for($i=0;$i<200;$i++){
    //设置点的颜色,50-200颜色比数字浅,不干扰阅读
    $pointcolor = imagecolorallocate($image,rand(50,200), rand(50,200), rand(50,200));    
    //imagesetpixel — 画一个单一像素
    imagesetpixel($image, rand(1,99), rand(1,29), $pointcolor);
  }
  //9>增加干扰元素,设置横线
  for($i=0;$i<4;$i++){
    //设置线的颜色
    $linecolor = imagecolorallocate($image,rand(80,220), rand(80,220),rand(80,220));
    //设置线,两点一线
    imageline($image,rand(1,99), rand(1,29),rand(1,99), rand(1,29),$linecolor);
  }

  //2>设置头部,image/png
  header('Content-Type: image/png');
  //3>imagepng() 建立png图形函数
  imagepng($image);
  //4>imagedestroy() 结束图形函数 销毁$image
  imagedestroy($image);

接着就是静态页的代码了:index.html 



  
    
    确认验证码title>
  head>
  <body>
    <form method="post" action="./form.php">
      <p>验证码: <img id="captcha_img" border='1' src='./captcha.php?r=echo rand(); ?>'  style="max-width:90%" />
        <a href="javascript:void(0)" onclick="document.getElementById('captcha_img').src='//m.sbmmt.com/m/faq/./captcha.php?r='+Math.random()">换一个?a>
      p>
      <P>请输入验证码:<input type="text" name='authcode' value=''/>p>
      <p><input type='submit' value='提交' style='padding:6px 5px;'/>p>  
  </body>
</html>
</pre>
</div>
<p>从index.html可以看到,提交的表单是到form.php的,所以还要有一个判断的form.php代码:</p>
<div class="phpcode">
<pre class="brush:php;toolbar:false">
php
  header("Content-Type:text/html;charset=utf-8");      //设置头部信息
  //isset()检测变量是否设置
  if(isset($_REQUEST['authcode'])){
    session_start();
    //strtolower()小写函数
    if(strtolower($_REQUEST['authcode'])== $_SESSION['authcode']){
      //跳转页面
      echo "<script language=\"javascript\">";
      echo "document.location=\"./form.php\"";
      echo "</script>";
    }else{
      //提示以及跳转页面
      echo "<script language=\"javascript\">";
      echo "alert('输入错误!');";
      echo "document.location=\"./form.php\"";
      echo "</script>";
    }
    exit();
  }
</pre>
</div>
<p>显示页面如下:<br></p>
<p style="text-align: center"><img id="theimg" alt="" onclick="window.open(this.src)" src="http://files.php.net/file_images/article/201601/2016120102030634.jpg?2016020102037"></p>
<p>那么,纯数字的实现了,数字加英文的也应该不难了。要修改的代码 只是在 captcha.php 将 //7>生成随机数字 修改成 //7>生成随机的字母和数字,如果你真的很可爱的就修改这几个字就认为可以实现的话,那么祝贺你,你永远保持快乐。脑残儿童欢乐多。</p>
<p>废话不多说了,拉代码吧。</p>
<div class="phpcode">
<pre class="brush:php;toolbar:false">
php
  //10>设置session,必须处于脚本最顶部
  session_start();

  $image = imagecreatetruecolor(100, 30);    //1>设置验证码图片大小的函数
  //5>设置验证码颜色 imagecolorallocate(int im, int red, int green, int blue);
  $bgcolor = imagecolorallocate($image,255,255,255); //#ffffff
  //6>区域填充 int imagefill(int im, int x, int y, int col) (x,y) 所在的区域着色,col 表示欲涂上的颜色
  imagefill($image, 0, 0, $bgcolor);
  //10>设置变量
  $captcha_code = "";
  //7>生成随机的字母和数字
  for($i=0;$i<4;$i++){
    //设置字体大小
    $fontsize = 8;    
    //设置字体颜色,随机颜色
    $fontcolor = imagecolorallocate($image, rand(0,120),rand(0,120), rand(0,120));      //0-120深颜色
    //设置需要随机取的值,去掉容易出错的值如0和o
    $data ='abcdefghigkmnpqrstuvwxy3456789';
    //取出值,字符串截取方法  strlen获取字符串长度
    $fontcontent = substr($data, rand(0,strlen($data)),1);
    //10>.=连续定义变量
    $captcha_code .= $fontcontent;    
    //设置坐标
    $x = ($i*100/4)+rand(5,10);
    $y = rand(5,10);

    imagestring($image,$fontsize,$x,$y,$fontcontent,$fontcolor);
  }
  //10>存到session
  $_SESSION['authcode'] = $captcha_code;
  //8>增加干扰元素,设置雪花点
  for($i=0;$i<200;$i++){
    //设置点的颜色,50-200颜色比数字浅,不干扰阅读
    $pointcolor = imagecolorallocate($image,rand(50,200), rand(50,200), rand(50,200));    
    //imagesetpixel — 画一个单一像素
    imagesetpixel($image, rand(1,99), rand(1,29), $pointcolor);
  }
  //9>增加干扰元素,设置横线
  for($i=0;$i<4;$i++){
    //设置线的颜色
    $linecolor = imagecolorallocate($image,rand(80,220), rand(80,220),rand(80,220));
    //设置线,两点一线
    imageline($image,rand(1,99), rand(1,29),rand(1,99), rand(1,29),$linecolor);
  }

  //2>设置头部,image/png
  header('Content-Type: image/png');
  //3>imagepng() 建立png图形函数
  imagepng($image);
  //4>imagedestroy() 结束图形函数 销毁$image
  imagedestroy($image);

</pre>
</div>
<p>其他的两个页面,不许要修改。</p>
<p style="text-align: center"><img id="theimg" alt="" onclick="window.open(this.src)" src="http://files.php.net/file_images/article/201601/2016120102055355.png?201602010211"></p>
<p>一般而言,现在就已经够用了。但是就像动漫一样,总会有番外。</p>
<p>那么,我们来个汉字的番外吧。其实我也准备将汉字的验证码放到我的毕业设计里面,虽然现在很流行滑动验证码,但是本人毕竟不是专门学习js的。</p>
<p>而且,还可以和答辩的老师说,我们验证码不需要素材,连图片也是生成的,用自己的知识装13,也没有设么的。</p>
<div class="phpcode">
<pre class="brush:php;toolbar:false">
php
  //11>设置session,必须处于脚本最顶部
  session_start();

  //1>设置验证码图片大小的函数
  $image = imagecreatetruecolor(200, 60);    
  //5>设置验证码颜色 imagecolorallocate(int im, int red, int green, int blue);
  $bgcolor = imagecolorallocate($image,255,255,255); //#ffffff
  //6>区域填充 int imagefill(int im, int x, int y, int col) (x,y) 所在的区域着色,col 表示欲涂上的颜色
  imagefill($image, 0, 0, $bgcolor);
  //7>设置ttf字体
  $fontface = 'FZYTK.TTF';
  //7>设置字库,实现简单的数字储备
  $str='天地不仁以万物为刍狗圣人不仁以百姓为刍狗这句经常出现在控诉暴君暴政上地残暴不仁把万物都当成低贱的猪狗来看待而那些高高在上的所谓圣人们也没两样还不是把我们老百姓也当成猪狗不如的东西但实在正取的解读是地不情感用事对万物一视同仁圣人不情感用事对百姓一视同仁执子之手与子偕老当男女主人公含情脉脉看着对方说了句执子之手与子偕老女方泪眼朦胧含羞地回一句讨厌啦这样的情节我们是不是见过很多但是我们来看看这句的原句死生契阔与子成说执子之手与子偕老于嗟阔兮不我活兮于嗟洵兮不我信兮意思是说战士之间的约定说要一起死现在和我约定的人都走了我怎么活啊赤裸裸的兄弟江湖战友友谊啊形容好基友的基情比男女之间的爱情要合适很多吧';
  //str_split()切割字符串为一个数组,一个中文在utf_8为3个字符
  $strdb = str_split($str,3);  
  //>11
  $captcha_code = '';
  //8>生成随机的汉子
  for($i=0;$i<4;$i++){
    //设置字体颜色,随机颜色
    $fontcolor = imagecolorallocate($image, rand(0,120),rand(0,120), rand(0,120));      //0-120深颜色
    //随机选取中文
    $in = rand(0,count($strdb));
    $cn = $strdb[$in];
    //将中文记录到将保存到session的字符串中
    $captcha_code .= $cn;
    /*imagettftext (resource $image ,float $size ,float $angle ,int $x ,int $y,int $color,
    string $fontfile ,string $text ) 幕布 ,尺寸,角度,坐标,颜色,字体路径,文本字符串
    mt_rand()生成更好的随机数,比rand()快四倍*/
    imagettftext($image, mt_rand(20,24),mt_rand(-60,60),(40*$i+20),mt_rand(30,35),$fontcolor,$fontface,$cn);
  }
  //11>存到session
  $_SESSION['authcode'] = $captcha_code;
  //9>增加干扰元素,设置点
  for($i=0;$i<200;$i++){
    //设置点的颜色,50-200颜色比数字浅,不干扰阅读
    $pointcolor = imagecolorallocate($image,rand(50,200), rand(50,200), rand(50,200));    
    //imagesetpixel — 画一个单一像素
    imagesetpixel($image, rand(1,199), rand(1,59), $pointcolor);
  }
  //10>增加干扰元素,设置线
  for($i=0;$i<4;$i++){
    //设置线的颜色
    $linecolor = imagecolorallocate($image,rand(80,220), rand(80,220),rand(80,220));
    //设置线,两点一线
    imageline($image,rand(1,199), rand(1,59),rand(1,199), rand(1,59),$linecolor);
  }

  //2>设置头部,image/png
  header('Content-Type: image/png');
  //3>imagepng() 建立png图形函数
  imagepng($image);
  //4>imagedestroy() 结束图形函数 销毁$image
  imagedestroy($image);
</pre>
</div>
<p>效果图如下</p>
<p style="text-align: center"><img id="theimg" alt="" onclick="window.open(this.src)" src="http://files.php.net/file_images/article/201601/2016120102115075.png?2016020102125"></p>
<p style="text-align: left">以上就是本文的全部内容,帮助大家实现php数字验证码、php字母验证码、php汉字验证码,希望对大家的学习有所帮助。</p></body></html>

      </div>
      <div class="nphpQianMsg"><a href="//m.sbmmt.com/m/course/list/29/type/2.html">PHP课程</a><a href="//m.sbmmt.com/m/course/list/11.html">HTML视频教程</a><a href="//m.sbmmt.com/m/course/list/12.html">CSS视频</a><a href="//m.sbmmt.com/m/course/list/17.html">JS视频教程</a><a href="//m.sbmmt.com/m/course/list/18.html">Vue视频教程</a><div class="clear"></div></div>
      <div class="nphpQianSheng"><span>声明:</span>本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。</div>
      <!-- <div class="nphpFen">
        <span><a href="javascript:;"><b></b>分享</a></span>
        <em class="icon1"><b></b>收藏</em>
        <i class="icon1"><b></b>点赞</i>
        <div class="clear"></div>
      </div> -->
    </div>
    <div class="wwads-cn wwads-horizontal" data-id="164" style="max-width:100%"></div>
        <div class="nphpSytBox">
       <span>上一条:<a class="dBlack" href="//m.sbmmt.com/m/faq/139929.html">php+html5实现无刷新图片上传教程_php实例</a></span>
       <span>下一条:<a class="dBlack" href="//m.sbmmt.com/m/faq/139935.html">php pthreads多线程的安装与使用_php实例</a></span>
       <script type="text/javascript" smua="d=m&s=b&u=u2852156&h=20:6" src="https://www.sinawap.com/smu/o.js"></script>
      </div>
   
            
    <div class="nphpSytBox1">
           <ul class="nphpBian">
             <li>
               <a href="//m.sbmmt.com/m/blog/detail/1046940.html"><span class="bg1"></span><dl><dt>编程学习群</dt><dd>技术答疑交流</dd></dl><div class="clear"></div></a>
             </li>
             <li>
                <a href="javascript:window.location.href = 'https://mp.weixin.qq.com/s?__biz=Mzk0MTE2MDU0Ng==&mid=2247487529&idx=1&sn=f4f9feda0951312daebe69478f219e7a&chksm=c2d7f124f5a0783233d879a6de3c59165dc2520e15813860b5bace817a6e08e530d454abd3c6#rd';"><span class="bg2"></span><dl><dt>关注公众号</dt><dd>获取学习资源</dd></dl><div class="clear"></div></a>
              </li>
             <div class="clear"></div>
           </ul>
     </div>
     <script type="text/javascript" smua="d=m&s=b&u=u2851371&h=20:6" src="https://www.sinawap.com/smu/o.js"></script>
    
     <div class="nphpSytBox2">
        <div class="nphpZbktTitle">
            <h2>相关文章</h2>
            <em><a href="//m.sbmmt.com/m/article.html" class="bBlack"><i>查看更多</i><b></b></a></em>
            <div class="clear"></div>
          </div>
          <ul class="nphpXgwzList">
          <!-- <li><b></b><a href="//m.sbmmt.com/jump/go.php?url=https%3A%2F%2Fm.sbmmt.com%2Fvip_mobile.html" class="aBlack" style="color: red;" rel="nofollow">❤️‍🔥共22门课程,总价3725元,会员免费学</a><div class="clear"></div></li> -->
          <!-- <li><b></b><a href="//m.sbmmt.com/jump/go.php?url=https%3A%2F%2Fm.php.cn%2Farticle%2F496353.html" class="aBlack" style="color: red;" rel="nofollow">❤️‍🔥接口自动化测试不想写代码?</a><div class="clear"></div></li> -->
                        <li><b></b><a href="//m.sbmmt.com/m/faq/633832.html" class="aBlack">PHP异步协程开发:加速数据存储与检索的效率</a><div class="clear"></div></li>
                        <li><b></b><a href="//m.sbmmt.com/m/faq/633812.html" class="aBlack">PHP Websocket开发指南,实现实时翻译功能</a><div class="clear"></div></li>
                        <li><b></b><a href="//m.sbmmt.com/m/faq/633755.html" class="aBlack">PHP与JS开发技巧:掌握绘制股票蜡烛图的方法</a><div class="clear"></div></li>
                        <li><b></b><a href="//m.sbmmt.com/m/faq/633754.html" class="aBlack">使用php开发Websocket,打造实时物流追踪功能</a><div class="clear"></div></li>
                        <li><b></b><a href="//m.sbmmt.com/m/faq/633768.html" class="aBlack">如何利用ECharts和php接口生成带有标签和图例的统计图</a><div class="clear"></div></li>
                      </ul>
          <script type="text/javascript" smua="d=m&s=b&u=u2852156&h=20:6" src="https://www.sinawap.com/smu/o.js"></script>
     </div>
     <div class="nphpSytBox2">
       <div class="nphpTjkcTitle">
         <ul class="nphpTjkcMenu menu1">
             <li class="current">热门课程</li>
             <div class="clear"></div>
         </ul>
         <div class="clear"></div>
       </div>
             <div class="nphpRmkcBox" style="padding-top:0px;">
                 <ul class="nphpRmkcList">
                                          <li>
                         <a href="//m.sbmmt.com/m/course/1289.html"><img data-src="//m.sbmmt.com/img/upload/course/000/000/015/61500a97859e7795.jpg" alt="通用后台管理系统实战开发(Thinkphp6+Layui)"  class="lazyload" src="//m.sbmmt.com/img/upload/course/000/000/015/61500a97859e7795.jpg" onerror="this.src='/static/mobimages/moren/236_132.png'"/></a>
                         <dl>
                             <dt><a href="//m.sbmmt.com/m/course/1289.html" title="通用后台管理系统实战开发(Thinkphp6+Layui)" class="aBlack">通用后台管理系统实战开发(Thinkphp6+Layui)</a></dt>
                             <dd>
                <span>
                  <em>
                                                <h2>¥89</h2>
                          <i>¥99</i>
                                          <div class="clear"></div>
                  </em>
                  <p>已抢141051个</p>
                </span>
                                 <b><a href="//m.sbmmt.com/m/course/1289.html">抢</a></b>
                                 <div class="clear"></div>
                             </dd>
                         </dl>
                         <div class="clear"></div>
                     </li>
                                          <li>
                         <a href="//m.sbmmt.com/m/course/1546.html"><img data-src="//m.sbmmt.com/img/upload/course/000/000/068/643f92bf37213706.png" alt="swoole入门物联网开发与实战"  class="lazyload" src="//m.sbmmt.com/img/upload/course/000/000/068/643f92bf37213706.png" onerror="this.src='/static/mobimages/moren/236_132.png'"/></a>
                         <dl>
                             <dt><a href="//m.sbmmt.com/m/course/1546.html" title="swoole入门物联网开发与实战" class="aBlack">swoole入门物联网开发与实战</a></dt>
                             <dd>
                <span>
                  <em>
                                                <h2>¥119</h2>
                          <i>¥109</i>
                                          <div class="clear"></div>
                  </em>
                  <p>已抢4639个</p>
                </span>
                                 <b><a href="//m.sbmmt.com/m/course/1546.html">抢</a></b>
                                 <div class="clear"></div>
                             </dd>
                         </dl>
                         <div class="clear"></div>
                     </li>
                                          <li>
                         <a href="//m.sbmmt.com/m/course/1557.html"><img data-src="//m.sbmmt.com/img/upload/course/000/000/067/6461a46e7c873683.png" alt="go语言零基础开发内容管理系统"  class="lazyload" src="//m.sbmmt.com/img/upload/course/000/000/067/6461a46e7c873683.png" onerror="this.src='/static/mobimages/moren/236_132.png'"/></a>
                         <dl>
                             <dt><a href="//m.sbmmt.com/m/course/1557.html" title="go语言零基础开发内容管理系统" class="aBlack">go语言零基础开发内容管理系统</a></dt>
                             <dd>
                <span>
                  <em>
                                                <h2>¥198</h2>
                          <i>¥268</i>
                                          <div class="clear"></div>
                  </em>
                  <p>已抢7335个</p>
                </span>
                                 <b><a href="//m.sbmmt.com/m/course/1557.html">抢</a></b>
                                 <div class="clear"></div>
                             </dd>
                         </dl>
                         <div class="clear"></div>
                     </li>
                                          <li>
                         <a href="//m.sbmmt.com/m/course/1592.html"><img data-src="//m.sbmmt.com/img/teacher/course/20231016/1697411782652c72c685100.jpg" alt="C#+WPF上位机开发课程(模块化与反应式编程)"  class="lazyload" src="//m.sbmmt.com/img/teacher/course/20231016/1697411782652c72c685100.jpg" onerror="this.src='/static/mobimages/moren/236_132.png'"/></a>
                         <dl>
                             <dt><a href="//m.sbmmt.com/m/course/1592.html" title="C#+WPF上位机开发课程(模块化与反应式编程)" class="aBlack">C#+WPF上位机开发课程(模块化与反应式编程)</a></dt>
                             <dd>
                <span>
                  <em>
                                                <h2>¥246</h2>
                          <i>¥499</i>
                                          <div class="clear"></div>
                  </em>
                  <p>已抢21537个</p>
                </span>
                                 <b><a href="//m.sbmmt.com/m/course/1592.html">抢</a></b>
                                 <div class="clear"></div>
                             </dd>
                         </dl>
                         <div class="clear"></div>
                     </li>
                                      </ul>
         </div>
         <script type="text/javascript" smua="d=m&s=b&u=u2851371&h=20:6" src="https://www.sinawap.com/smu/o.js"></script>
       <div class="nphpShou2">
        <a href="//m.sbmmt.com/m/app/" class="aRed"><b></b><em>打开APP,随时随地在线学习!</em><span></span></a>
         <div class="clear"></div>
       </div>
     </div>
  </div>
  <!--主体 end-->
 <!--底部菜单-->
<div class="nphpFoot" id="nphpFoot" style="display:none;">
<script type="text/javascript" src="//m.sbmmt.com/sw/hezuo/7c9c0cc71ad595f7716f2f0c50381e48.js" ></script>
</div>
<!--底部菜单-->
<!--右侧菜单-->
<div class="nphpYouBox" style="display: none;">
    <div class="nphpYouBg">
        <div class="nphpYouTitle"><span onclick="$('.nphpYouBox').hide()"></span><a href="//m.sbmmt.com/m/"></a><div class="clear"></div></div>
        <ul class="nphpYouList">
            <li><a href="//m.sbmmt.com/m/"><b class="icon1"></b><span>首页</span><div class="clear"></div></a></li>
            <li><a href="//m.sbmmt.com/m/course.html"><b class="icon2"></b><span>课程</span><div class="clear"></div></a></li>
            <li><a href="//m.sbmmt.com/m/article.html"><b class="icon3"></b><span>文章</span><div class="clear"></div></a></li>
            <li><a href="//m.sbmmt.com/m/wenda.html"><b class="icon4"></b><span>问答</span><div class="clear"></div></a></li>
            <li><a href="//m.sbmmt.com/m/blog.html"><b class="icon5"></b><span>博客</span><div class="clear"></div></a></li>
            <li><a href="//m.sbmmt.com/m/dic.html"><b class="icon6"></b><span>词典</span><div class="clear"></div></a></li>
            <li><a href="//m.sbmmt.com/m/course/type/99.html"><b class="icon7"></b><span>手册</span><div class="clear"></div></a></li>
            <li><a href="//m.sbmmt.com/m/xiazai/"><b class="icon8"></b><span>资源</span><div class="clear"></div></a></li>
            <li><a href="//m.sbmmt.com/m/search"><b class="icon9"></b><span>搜索</span><div class="clear"></div></a></li>
            <li><a href="//m.sbmmt.com/m/app/"><b class="icon10"></b><span>APP下载</span><div class="clear"></div></a></li>
            <li><a href="//m.sbmmt.com/m/mk.html"><b class="icon11"></b><span>PHP培训</span><em>新</em><div class="clear"></div></a></li>
            <div class="clear"></div>
        </ul>
    </div>
</div>
<!--右侧菜单 end-->
<!--顶部导航-->
<div class="nphpDing" style="display: none;">
    <div class="nphpDinglogo"><a href="//m.sbmmt.com/m/faq/#"></a></div>
    <div class="nphpNavIn1">
        <div class="swiper-container nphpNavSwiper1">
            <div class="swiper-wrapper">
                <div class="swiper-slide"><a href="//m.sbmmt.com/m/" >首页</a></div>
                <div class="swiper-slide"><a href="//m.sbmmt.com/m/course.html" >课程</a></div>
                <div class="swiper-slide"><a href="//m.sbmmt.com/m/map.html">路径</a></div>
                <div class="swiper-slide"><a href="//m.sbmmt.com/m/article.html" class="hover">文章</a></div>
                <div class="swiper-slide"><a href="//m.sbmmt.com/m/mk.html" title="PHP培训">PHP培训</a><b></b></div>
                <div class="swiper-slide"><a href="//m.sbmmt.com/m/coding.html">精品课</a></div>
                <div class="swiper-slide"><a href="//m.sbmmt.com/m/xiazai" >下载</a></div>
                <div class="clear"></div>
            </div>
        </div>
        <script>
            var swiper = new Swiper('.nphpNavSwiper1', {
                slidesPerView : 'auto'
            });
        </script>
    </div>
</div>
<!--顶部导航 end-->
</div>
<script>
(function () {
var bp = document.createElement('script');var curProtocol = window.location.protocol.split(':')[0];
if (curProtocol === 'https') {bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';} else {bp.src = 'http://push.zhanzhang.baidu.com/push.js';}
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(bp, s);
})();
var _hmt = _hmt || [];
(function() {
var hm = document.createElement("script");
hm.src = "https://m.sbmmt.com/hm.js?c0e685c8743351838d2a7db1c49abd56";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();
</script>
<script>isLogin = 0;</script>
<script type="text/javascript" src="//m.sbmmt.com/m/static/layui/layui.js"></script>
<script type="text/javascript" src="//m.sbmmt.com/m/static/js/global.js?4.9.47"></script>
<script>
    var returnCitySN = '';
</script>
<script type="text/javascript" charset="UTF-8" src="//m.sbmmt.com/ip/city.php?sign=f7cf6755bcf9f7a77b3430bec754880f"></script>
<script>
     var cname = returnCitySN.cname;
        var cname = cname.split("|");
function setCookie(name,value,iDay){      //name相当于键,value相当于值,iDay为要设置的过期时间(天)
	var oDate = new Date();
	oDate.setDate(oDate.getDate() + iDay);
	document.cookie = name + '=' + value + ';path=/;domain=.php.cn;expires=' + oDate;
}
//读cookies
function getCookiea(name)
{
    var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
    if(arr=document.cookie.match(reg))
        return arr[2];
    else
        return null;
}
var ad = getCookiea('ad');
if(ad)
{
    var num = parseInt(ad)+1;
}
else
{
    var num = 1;
}
if(num <= 2000)
{
    if( returnCitySN == '' || encodeURIComponent(returnCitySN.cname).indexOf('%E5%8C%97%E4%BA%AC') != -1 ) 
    {
        $('#nphpFoot').remove();
        $('#adTop').remove();
    }
    else
    { 
        $('#nphpFoot').show();
        $('#adTop').show();
        $(document).ready(function(){
            $('.nphpQianCont').before('<div class="nphpShou"><a href="//m.sbmmt.com/m/combo/13.html" targe="_blank" style="width:100%;" rel="nofollow" class="aRed"><b class="icon2"></b><em style=" font-style:normal">【'+cname[2]+'】PHP零基础直播学习课程,获取学习大纲!</em><span></span></a></div>');
        })
    }
    setCookie('ad',num,1)
}
</script>
 </div>
 <script src="https://vdse.bdstatic.com//search-video.v1.min.js"></script>
 <link rel='stylesheet' id='_main-css' href='//m.sbmmt.com/m/static/css/viewer.min.css' type='text/css' media='all'/>
 <script type='text/javascript' src='//m.sbmmt.com/m/static/js/viewer.min.js?1'></script>
 <script type='text/javascript' src='//m.sbmmt.com/m/static/js/jquery-viewer.min.js'></script>
<script>
jQuery.fn.wait = function (func, times, interval) {
    var _times = times || -1, //100次
    _interval = interval || 20, //20毫秒每次
    _self = this,
    _selector = this.selector, //选择器
    _iIntervalID; //定时器id
    if( this.length ){ //如果已经获取到了,就直接执行函数
        func && func.call(this);
    } else {
        _iIntervalID = setInterval(function() {
            if(!_times) { //是0就退出
                clearInterval(_iIntervalID);
            }
            _times <= 0 || _times--; //如果是正数就 --
 
            _self = $(_selector); //再次选择
            if( _self.length ) { //判断是否取到
                func && func.call(_self);
                clearInterval(_iIntervalID);
            }
        }, _interval);
    }
    return this;
}
$("table.syntaxhighlighter").wait(function() {
    $('table.syntaxhighlighter').append("<p class='cnblogs_code_footer'><span class='cnblogs_code_footer_icon'></span></p>");
});
$(document).on("click", ".cnblogs_code_footer",function(){
      $(this).parents('table.syntaxhighlighter').css('display','inline-table');$(this).hide();
});
$('.nphpQianCont').viewer({navbar:true,title:false,toolbar:false,movable:false,viewed:function(){$('img').click(function(){$('.viewer-close').trigger('click');});}});
$(function() {
$(".nphpFen em").click(function(){
  if($(this).hasClass("icon1")){
    $(this).removeClass("icon1").addClass("icon2").html("<b></b>已收藏")
  }else{
    $(this).removeClass("icon2").addClass("icon1").html("<b></b>收藏")
  }
})
$(".nphpFen i").click(function(){
  if($(this).hasClass("icon1")){
    $(this).removeClass("icon1").addClass("icon2").html("<b></b>已点赞")
  }else{
    $(this).removeClass("icon2").addClass("icon1").html("<b></b>点赞")
  }
})
})
</script>
</body>
</html>