PHP 시 뮬 레이 션 로그 인 기능 실례 상세 설명

이 글 의 실례 는 PHP 시 뮬 레이 션 로그 인 기능 을 다 루 었 다.여러분 께 참고 하도록 공유 하 겠 습 니 다.구체 적 으로 는 다음 과 같 습 니 다.
설명:이 아 날로 그 로그 인 인 스 턴 스 는 인증 코드 가 없 는 아 날로 그 로그 인 스 턴 스 에 만 적 용 됩 니 다.
이 프로그램의 기본 기능 은 대학교 도서관 사이트 에 모 의 접속 하여 독자 정보 와 대출 정 보 를 얻 는 것 이다.
프로그램 캡 처:


디 렉 터 리 구조:

login.php

<form method="post" class="am-form" action="judge.php">
   <label for="sid">  :</label>
   <input type="text" name="number" id="sid" value="">
   <br>
   <label for="password">  :</label>
   <input type="password" name="passwd" id="password" value="">
   <br>
   <div class="am-cf">
    <input type="submit" name="" value="   " class="am-btn am-btn-primary am-btn-sm am-fl">
    <input type="submit" name="" value="     ^_^? " class="am-btn am-btn-default am-btn-sm am-fr">
   </div>
  </form>

judge.php

session_start();
require_once 'curl.php';
$url = "http://opac.lib.ustc.edu.cn/reader/redr_info.php";
$number = $_POST['number'];
$passwd = $_POST['passwd'];
$res = run_curl($url,$number,$passwd);
$pattern = '/<TD><span class=\"bluetext\">  :<\/span>(.*)<\/TD>/';
preg_match($pattern, $res,$arr1);
if(is_array($arr1)){
 $_SESSION['number'] = $number;
 $_SESSION['passwd'] = $passwd;
 $_SESSION['name'] = $arr1[1];
 echo "<script>window.location.href='index.php';</script>";
}else{
 echo "<script>history.go(-1);</script>";
}

curl.php

<?php
function run_curl($content_url,$number='',$passwd=''){
  $cookie_file = tempnam('./temp','cookie');
  $url = "http://opac.lib.ustc.edu.cn/reader/redr_verify.php";
  $ch = curl_init($url);
  curl_setopt($ch, CURLOPT_HEADER, 0);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
  $post_fileds = "number=$number&passwd=$passwd&select=bar_no";
  curl_setopt($ch,CURLOPT_POST,1);
  curl_setopt($ch,CURLOPT_POSTFIELDS,$post_fileds);
  curl_setopt($ch,CURLOPT_COOKIEFILE,$cookie_file);
  curl_setopt($ch,CURLOPT_COOKIEJAR,$cookie_file);
  $content = curl_exec($ch);
  curl_close($ch);
  $ch = curl_init($content_url);
  curl_setopt($ch, CURLOPT_HEADER, 0);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
  curl_setopt($ch,CURLOPT_COOKIEFILE,$cookie_file);
  curl_setopt($ch,CURLOPT_COOKIEJAR,$cookie_file);
  $res = curl_exec($ch);
  curl_close($ch);
  return $res;
}

index.php

<?php
  session_start();
  $number = $_SESSION['number'];
  $passwd = $_SESSION['passwd'];
  $username = $_SESSION['name'];
  if($number==''||$passwd==''||$username==''){
    echo "<script>window.location.href='login.php';</script>";
    exit();
  }
  require_once 'curl.php';
  header('Content-type:text/html;charset=utf-8');
  $url = "http://opac.lib.ustc.edu.cn/reader/book_lst.php";
  $res = run_curl($url,$number,$passwd); //  curl    
  $pattern = '/<td class="whitetext" width="35%"><a class="blue" href="(.*)" rel="external nofollow" >(.*)<\/a>/';//          
  preg_match_all($pattern, $res,$book_arr);
  $booklist = array();
  $booklist = $book_arr[2];  //      
  //var_dump($booklist);
  $pattern = '/<font color=(red|)>(.*)<\/font>/';//          
  preg_match_all($pattern, $res,$date_arr);
  $datelist = array();
  $datelist = $date_arr[2];  //       
  $taglist = array();
  $taglist = $date_arr[1];  //      
  //var_dump($date_arr);
?>

logout.php

<?php
session_start();
$_SESSION = array();
session_destroy();
?>
<script>window.location.href='login.php'</script>

더 많은 PHP 관련 내용 에 관심 이 있 는 독자 들 은 본 사이트 의 주 제 를 볼 수 있다.
본 논문 에서 말 한 것 이 여러분 의 PHP 프로 그래 밍 에 도움 이 되 기 를 바 랍 니 다.

좋은 웹페이지 즐겨찾기