我正在开发一个与Windows,OSX和Android一起使用的UniFi wifi登录门户,但是在iOS上失败了。 iOS中的所有会话数据均为NULL。
这是索引页面:
<?php
// PHP SCRIPT FOR SIMPLE PORTAL
session_start();
$_SESSION['id'] = $_GET['id']; // User's MAC address
$_SESSION['ap'] = $_GET['ap']; // AP mac
$_SESSION['ssid'] = $_GET['ssid']; // SSID the user is on
$_SESSION['time'] = $_GET['t']; // Time the user attempted a request of the portal
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<title>WI-FI Login</title>
</head>
<body class="login-page">
<div class="login-content content-box">
<form name="login" action="authorized.php" method="post">
<div class="form-controls">
<!-- submit (only for no authentication) -->
<section id="buttons">
<input type="submit" name="connect" value="LOGIN" id="submitbtn" class="submitbtn" tabindex="3" />
<br style="clear:both;">
</section>
</div>
</form>
</div>
</body>
</html>
这里是authorized.php:
<?php
session_start();
function sendAuthorization($id, $minutes)
{
$unifiServer = 'https://localhost:8443';
$unifiUser = 'username';
$unifiPass = 'password';
// 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, 1);
// Login to the UniFi controller
curl_setopt($ch, CURLOPT_URL, "$unifiServer/api/login");
$data = json_encode(array("username" => $unifiUser, "password" => $unifiPass));
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
// 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/s/default/cmd/stamgr');
curl_setopt($ch, CURLOPT_POSTFIELDS, 'json='.$data);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_exec ($ch);
// Logout of the UniFi Controller
curl_setopt($ch, CURLOPT_URL, $unifiServer.'/logout');
curl_exec ($ch);
curl_close ($ch);
unset($ch);
}
if ($_POST) // Check to see if the form has been posted to
{
ob_start();
echo sendAuthorization($_SESSION['id'], (12*60));
ob_end_clean();
}
?>
<p>Authorized!</p>
<p><?php echo $_SESSION['id']; ?></p> <!-- NULL on iOS -->
有什么建议吗?我正在运行带有IIS的Windows服务器 - 这可能是个问题吗?
更新
似乎是一个会话问题。 session_start
始终返回TRUE,但iOS设备上的session_id
更改。为什么这只发生在iOS上?
答案 0 :(得分:0)
使用以下内容设置会话cookie似乎解决了问题:
// Set a session cookie:
$lifetimecookie = 180; // 3 minutes
setcookie(session_name(), session_id(), time()+$lifetimecookie);