我正在unifi AC中创建一个外部门户,用户将在其中进行身份验证,然后如果它们存在,他们将被允许使用互联网连接有时问题是在用户通过身份验证后我得到了一些允许的代码用户使用互联网,但他们不适合我。 所以用户在外部门户中进行了身份验证,但不允许启动 使用互联网应该允许用户开始使用互联网的代码是 在函数sendAuthentication中。
login.php源代码。
<?php session_start();
require_once('dbconnect.php');
$username = trim($_POST['username']);
$password = trim(md5($_POST['pass']));
$query = "select * from students where email='".$username."' && password='".$password."'";
$result = mysql_query($query) or die (mysql_error());
$row = mysql_fetch_array($result);
if($username === $row['email'] && $password === $row['password']){
//Minutes to authorize, change to suit your needs
echo '<script language="javascript">';
echo 'alert("Successfully login")';
echo '</script>';
sendAuthorization($_SESSION['id'], (12*60));
return true;
}
else{
$_SESSION['error']=TRUE;
header('location:http://b4w.uhuruone.co.tz/guest/s/default/');
}
function sendAuthorization($id, $minutes)
{
$unifiServer = "https://41.38.13.78:8443";
$unifiUser = "bro4wote";
$unifiPass = "rt@b45w";
// Start Curl for login
$ch = curl_init();
// We are posting data
curl_setopt($ch, CURLOPT_POST, TRUE);
// Set up cookies
$cookie_file = "/tmp/unifi_cookie";
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
// Allow Self Signed Certs
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
// Force SSL3 only
curl_setopt($ch, CURLOPT_SSLVERSION, 3);
// Login to the UniFi controller
curl_setopt($ch, CURLOPT_URL, "$unifiServer/login");
curl_setopt($ch, CURLOPT_POSTFIELDS,
"login=login&username=$unifiUser&password=$unifiPass");
// send login command
curl_exec ($ch);
// Send user to authorize and the time allowed
$data = json_encode(array(
'cmd'=>'authorize-guest',
'mac'=>$id,
'minutes'=>$minutes));
// Send the command to the API
curl_setopt($ch, CURLOPT_URL, $unifiServer.'/api/cmd/stamgr');
curl_setopt($ch, CURLOPT_POSTFIELDS, 'json='.$data);
curl_exec ($ch);
// Logout of the UniFi Controller
curl_setopt($ch, CURLOPT_URL, $unifiServer.'/logout');
curl_exec ($ch);
curl_close ($ch);
unset($ch);
}
?>
<p>Connecting to the network...</p>
<script>
//allow time for the authorization to go through
setTimeout("location.href='http://www.Google.com'",6000);
</script>