【原】实验室签到PHP版本
表单
<html> <body> <h1>实验室自动签到测试</h1> <h2>输入学号和登录密码(建议自己改过密码后再来录入您的数据)</h2> <form action="mydb.php" method="post"> 学号: <input type="text" name="studentid" /> 登录密码: <input type="text" name="pw" /> <input type="submit" value="OK" /> </form> </body> </html>
数据库mydb.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43 |
<html> <body> <?php $host
= "localhost" ; $user
= "test" ; $pass
= "123456" ; $db
= "mydb" ; function
execute_query( $query ) { $r
= mysql_query( $query ); if
(! $r ) { echo
"Cannot execute query: $query\n" ; trigger_error(mysql_error()); } else
{ echo
"Query: $query executed\n" ; } } @ $r
= mysql_connect( $host , $user , $pass ); if
(! $r ) { echo
"Could not connect to server\n" ; trigger_error(mysql_error(), E_USER_ERROR); } else
{ //echo "Connection established\n"; } $r2
= mysql_select_db( $db ); if
(! $r2 ) { echo
"Cannot select database\n" ; trigger_error(mysql_error(), E_USER_ERROR); } else
{ //echo "Database selected\n"; } $query
= sprintf( "INSERT INTO lab VALUES(‘%s‘,‘%s‘)" ,mysql_real_escape_string( $_POST [ "studentid" ]), $_POST [ "pw" ]); //echo $query; @execute_query( $query ); mysql_close(); ?> </body> </html> |
执行签到签离 loginandout.php
<?php //签到签离的主要函数$qingdao=1的时候执行签到,为0时执行签离 function lablogin( $user, $password ,$qingdao=1) { if ( empty( $user ) || empty( $password ) ) { return 0; } // 登录 $ch = curl_init(); define( "COOKIEJAR", tempnam( "/tmp", "cookie" ) ); $url = ‘http://www.buptcnc.cn/login/login‘; $post_data = ‘user.VUserId=‘.$user.‘&user.VUserPassword=‘.$password.‘&x=24&y=16‘; curl_setopt( $ch, CURLOPT_REFERER, "http://www.buptcnc.cn/login/login" ); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_HEADER, 1); curl_setopt( $ch, CURLOPT_COOKIEJAR, COOKIEJAR ); curl_setopt( $ch, CURLOPT_TIMEOUT, 500 ); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt( $ch, CURLOPT_USERAGENT, USERAGENT ); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); define( "USERAGENT", $_SERVER[‘HTTP_USER_AGENT‘] ); curl_setopt($ch, CURLOPT_POST, 1); $output = curl_exec($ch); curl_close($ch); //echo $output; // 签到 $urlqingdao=‘http://10.104.5.63/LabManage/index/addattendance?vStuId=‘.$user; $curl2 = curl_init(); curl_setopt($curl2, CURLOPT_URL,$urlqingdao); curl_setopt($curl2, CURLOPT_HEADER, false); curl_setopt($curl2, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl2, CURLOPT_COOKIEFILE, COOKIEJAR); // $content = curl_exec($curl2); // 签离 $urlqingli=‘http://10.104.5.63/LabManage/index/addattendanceleave.action?vStuId=‘.$user; $curl3 = curl_init(); curl_setopt($curl3, CURLOPT_URL,$urlqingli); curl_setopt($curl3, CURLOPT_HEADER, false); curl_setopt($curl3, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl3, CURLOPT_COOKIEFILE, COOKIEJAR); // $content = curl_exec($curl3); if ($qingdao) { $content = curl_exec($curl2);//$qingdao为真时执行签到,为假时执行签离 }else{ $content = curl_exec($curl3); } } $host = "localhost"; $user = "test"; $pass = "123456"; $db = "mydb"; $r = mysql_connect($host, $user, $pass); if (!$r) { echo "Could not connect to server\n"; trigger_error(mysql_error(), E_USER_ERROR); } else { echo "Connection established\n"; } $r2 = mysql_select_db($db); if (!$r2) { echo "Cannot select database\n"; trigger_error(mysql_error(), E_USER_ERROR); } else { echo "Database selected\n"; } $query = "SELECT * FROM lab"; $rs = mysql_query($query); if (!$rs) { echo "Could not execute query: $query"; trigger_error(mysql_error(), E_USER_ERROR); } else { echo "Query: $query executed\n"; } while ($row = mysql_fetch_assoc($rs)) { // echo $row[‘Id‘] . " " . $row[‘Name‘] . " " . $row[‘Price‘] . "\n"; $hour=date("H"); if (in_array($hour,array(8,9,13,14))) { // echo $row[‘stdId‘]."开始签到".$row[‘pw‘]; echo $row[‘stdId‘]."开始签到"."\n"; lablogin($row[‘stdId‘],$row[‘pw‘],‘1‘);//执行签到 }else { // echo $row[‘stdId‘]."开始签离".$row[‘pw‘]; echo $row[‘stdId‘]."开始签离"."\n"; lablogin($row[‘stdId‘],$row[‘pw‘],‘0‘);//执行签离 } } mysql_close();
linux crontab:
35 8 * * 1-5 /usr/bin/php /var/www/loginandout.php35 11 * * 1-5 /usr/bin/php /var/www/loginandout.php35 13 * * 1-5 /usr/bin/php /var/www/loginandout.php 35 17 * * 1-5 /usr/bin/php /var/www/loginandout.php
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。