首页 > 编程技术 > php

php 模拟登陆

发布时间:2016-11-25 16:04

php 模拟登陆$url = "http://www.discuz.net/";
$useragent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; TheWorld)";
$cookie = "dznet_cookietime=2592000;dznet_onlineusernum=7816;dznet_sid=QtlC87;dznet_auth=6bbeCQrzGv4eliNMLgU%2FlGZSpzbrsauGO1l0OBp6VQw5p0bcEg0xd4slYCM2ks%2FL0YCVYSO7XP2z8GMaxkPDUbXZCWft;checkpm=1";
$ch= curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_COOKIE, $cookie);
curl_setopt($ch, CURLOPT_REFERER, "http://www.discuz.net/index.php");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_USERAGENT, $useragent);
curl_exec($ch);
$tempCn = curl_multi_getcontent($ch);
curl_close($ch);
echo  $tempCn;


<?php
class Excel{
    var $header = "<?xml version="1.0" encoding="UTF-8"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
 xmlns:x="urn:schemas-microsoft-com:office:excel"
 xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
 xmlns:html="http://www.w3.org/TR/REC-html40">";
    var $footer = "</Workbook>";
    var $lines = array ();
     var $worksheet_title = "Table1";
    function addRow ($array) {
        // 初始化列
        $cells = "";
       
        // foreach key -> write value into cells
        foreach ($array as $k => $v):
   
         // 加个字符串与数字的判断 避免生成的 excel 出现数字以字符串存储的警告
         if(is_numeric($v)) {
          // 防止首字母为 0 时生成 excel 后 0 丢失
          if(substr($v, 0, 1) == 0) {
           $cells .= "<Cell><Data ss:Type="String">" . $v . "</Data></Cell> ";
          } else {
           $cells .= "<Cell><Data ss:Type="Number">" . $v . "</Data></Cell> ";
          }
         } else {
             $cells .= "<Cell><Data ss:Type="String">" . $v . "</Data></Cell> ";
         }
        endforeach;
        // transform $cells content into one row
        $this->lines[] = "<Row> " . $cells . "</Row> ";
    }
 
    function addArray ($array) {
        // 返回数组并保存到单元格中去
        foreach ($array as $k => $v):
            $this->addRow ($v);
        endforeach;
    }
 
    function setWorksheetTitle ($title) {
      
        $title = preg_replace ("/[|:|/|?|*|[|]]/", "", $title);
        // 取得标题长度
        $title = substr ($title, 0, 31);
        // 赋值
        $this->worksheet_title = $title;
    }
 
    function generateXML ($filename) {
        header("Content-Type: application/vnd.ms-excel; charset=UTF-8");
        header("Content-Disposition: inline; filename="" . $filename . ".xls"");
        echo stripslashes ($this->header);
        echo " <Worksheet ss:Name="" . $this->worksheet_title . ""> <Table> ";
        echo "<Column ss:Index="1" ss:AutoFitWidth="0" ss:Width="110"/> ";
        echo implode (" ", $this->lines);
        echo "</Table> </Worksheet> ";
        echo $this->footer;
    }
}
/**
 *  CakePHP中使用方法
 *  注意 ** cakePHP 配置文件 define('DEBUG', 0);
 *
 *  vendor ('Excel');
 *  $doc = array (
 *       0 => array ('中国', '中国人', '中国人民', '123456');
 *  );
 *  $xls = new Excel;
 *  $xls->addArray ( $doc );
 *  $xls->generateXML ("mytest");
 */
/**
 *  非框架使用方法
 *
 *  require_once('excel.php');
 *  $doc = array (
 *       0 => array ('中国', '中国人', '中国人民', '123456');
 *  );
 *  $xls = new Excel;
 *  $xls->addArray ( $doc );
 *  $xls->generateXML ("mytest");
 */
?>
 function makeDirectory($directoryName) {
  $directoryName = str_replace("","/",$directoryName);
  $dirNames = explode('/', $directoryName);
  $total = count($dirNames) ;
  $temp = '';
  for($i=0; $i<$total; $i++) {
   $temp .= $dirNames[$i].'/';
   if (!is_dir($temp)) {
    $oldmask = umask(0);
    if (!mkdir($temp, 0777)) exit("不能建立目录 $temp");
    umask($oldmask);
   }
  }
  return true;
 }

ajax验证用户名二

<?php
header("Content-type:text/html;charset=gb2312");
require_once('inc/connect.php');
$xm=isset($_GET['txt'])?$_GET['txt']:'null';

if(preg_match("/^[".chr(0xa1)."-".chr(0xff)."]+$/", $xm)){
  echo("<div id='error'>对不起,不能使用中文作为用户名! </div>");
  exit();
 }
if($xm=='null' || $xm=='' || strlen($xm)>10 || strlen($xm)<3){
 echo("<div id='error'>对不起,用户由3-12Aa_zZ及数字组成! </div>");
 exit();
}else{
 $result=mysql_query("select m_uid from wk_member where m_uid='$xm' ") or die('Error !'.mysql_error());
 if(!mysql_num_rows($result)){
  echo("<div id='success'><font color=red>&nbsp;&nbsp;&nbsp;&nbsp;恭喜你!此用户可以注册!</font> </div>");
 }else{
  echo("<div id='error'>对不起,用户己被注册请选择其它名称!</div>");
 }
}

?>

本站原创: www.111cn.net 

现在我们把check.js文件代码来看看吧.

function c(){
  var uid =document.getElementById('uid').value;
  var pwd =document.getElementById('password').value;
  var pwd2=document.getElementById('password2').value;
  var mo =document.getElementById('mo').value;
  var name=document.getElementById('name').value;  
  
  if( uid=='' || uid.length>12 || uid.length<3 ){
    document.getElementById('u_info').innerHTML='<div id=error>昵称长度为3-12字符!</div>'; 
    return false;
  }else{
    document.getElementById('u_info').innerHTML='<div class="defult">用户名长度3-12位</div>';
  }
  
  
  if(pwd =='' || pwd!=pwd2 || pwd.length<6 || pwd.length>12){
    document.getElementById('p_info').innerHTML='<div id=error>密码不能为空或二次输入的密码不一致!</span>';
    return false;
  }else{
    document.getElementById('p_info').innerHTML='<div id=success></div>';
    document.getElementById('p_info1').innerHTML='<div id=success></div>';
  }
  
  if( mo.match(/^[0-9]{3,4}-[0-9]{7,8}$/) || mo.match(/^(((d{3}))|(d{3}-))?13d{9}$/) ){
    document.getElementById('m_info').innerHTML='<div id=success></div>';
  }else{
    document.getElementById('m_info').innerHTML='<div id=error>手机13875888888与座机(0731-888888)</span>';
    return false;
  }
  
  if( name=='' || name.length>12 || name.length<2 ){
    document.getElementById('n_info').innerHTML='<div id=error>请输入你的真实姓名!</span>';
    return false;    
  }else{
    document.getElementById('n_info').innerHTML='<div id=success></div>';
  }
  
 


}

var xmlHttp = false;

function ajaxcreate(){

try {
  xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
try {
  xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
 } catch (e2) {
  xmlHttp = false;
 }
 }

if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
  xmlHttp = new XMLHttpRequest();
 }
if(!xmlHttp){alert('Create Xmlhttp Fail ');return false;}
}


function ajax(){
 ajaxcreate();
 var xmvalue=document.getElementById("uid").value;
 var url="ajax_check.php?txt="+encodeURI(xmvalue);
 if (xmvalue== null || xmvalue.length>20 || xmvalue == "") return false;
 xmlHttp.open("POST",url,true);
 xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
 xmlHttp.send(xmvalue); 
 xmlHttp.onreadystatechange=returnstate; 
}
function returnstate(){
 if(xmlHttp.readyState != 4 ){
  document.getElementById("u_info").innerHTML="<div class=defult>正在验证请稍后...</div>";
 }
 if(xmlHttp.readyState == 4 ){
  document.getElementById("u_info").innerHTML=xmlHttp.responseText;
 }
}

标签:[!--infotagslink--]

您可能感兴趣的文章: