PHP 시 뮬 레이 션 로그 인 기능 실례 상세 설명
5045 단어 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 프로 그래 밍 에 도움 이 되 기 를 바 랍 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
laravel에 yo에서 angularJs&coffeescript를 사용할 수 있도록 한다.먼저 yo 명령을 사용할 수 있어야하므로 아래에서 설치 global에 설치한 곳에서 laravel의 프로젝트 루트로 이동. 클라이언트 코드를 관리하는 디렉토리를 만들고 이동합니다. 클라이언트 환경 만들기 이것으로 히...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.