Skip to content

Instantly share code, notes, and snippets.

@lizheming
Created October 25, 2012 15:44
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lizheming/3953515 to your computer and use it in GitHub Desktop.
Save lizheming/3953515 to your computer and use it in GitHub Desktop.
Srun login and logout by php
<?php
/*
*Creat At 2012/10/25 23:29
*Author: Austin
*URL: http://imnerd.org
*Mail: i@imnerd.org
*Description: Srun Authorize Login & Logout By PHP
*/
//网关登陆:http://abc.com/srun.php?do=login
//网关退出:http://abc.com/srun.php?do=logout
//将自己的账号,密码,Mac地址填写到两个分号中
//Mac地址的格式为aa:bb:cc:dd,全部为小写
define('username', '');
define('password', '');
define('mac', '');
/*下面的就不用改了,嘻嘻!*/
define('host', '202.204.105.195');
function curl($data, $url) {
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, TRUE);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
$result = curl_exec($curl);
curl_close($curl);
return $result;
}
switch($_GET['do']) {
case 'login':
$data = 'username='.username.'&password='.password.'&mac='.mac.'&n=99&type=3';
$url = 'http://'.host.':3333/cgi-bin/do_login';
$uid = curl($data, $url);
echo file_put_contents('uid.txt', $uid) ? 'Success!' : 'Failed!';
break;
case 'logout':
if(file_exists('uid.txt')) {
$uid = file_get_contents('uid.txt');
} else {
die('not login yet!');
}
$data = 'uid='.$uid;
$url = 'http://'.host.':3333/cgi-bin/do_logout';
$result = curl($data, $url);
print_r($result);
break;
default:
die('Bug for u!');
break;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment