强制性的“我是这个新手”。
我遇到一个问题,即在强制门户登录后,cookie似乎没有持久存在。 我设置了一个强制门户,将其放置在我们的Web服务器上,在2个cookie上存储mac和唯一ID,将它们重定向到其他地方进行身份验证,然后它们返回到我们的Web服务器,在其中我们查找该uid并返回唯一代码。 在Windows电脑上测试它可以正常工作,但是在android手机上则不能。 似乎在android手机上,我可以看到cookie已设置,在您通过wifi热点获得的默认浏览器上,因为我已经使该页面回显了该值。 但是,当我在chrome浏览器中手动输入网址时,它显示出cookie不再设置为任何值。 在2部Android手机和我的Windows笔记本电脑上进行了测试(再次正常工作)。 有什么想法吗?
这看起来像是一团糟。
这是他们登陆的第一页:
$sql = "select uid from table where mac =('$client_mac_address')";
$uidResult = $conn->query($sql);
if($uidResult->num_rows > 0) {
while($row = mysqli_fetch_array($uidResult)) {
$cookie_uid = "UID";
echo $row['uid'];
setcookie($cookie_uid,$row['uid'],time() + (86400 * 30),"/");
if(!isset($_COOKIE[$cookie_uid])) {
echo "Cookie named '" . $cookie_uid . "' is not set!";
} else {
echo "Cookie '" . $cookie_uid . "' is set!<br>";
echo "Value is: " . $_COOKIE[$cookie_uid];
echo $_COOKIE[$cookiename];
}
}
};
这是他们登陆的最后一页 我先获取他们的MAC,然后再使用它查找uid:
<?php
$cookiename = "UID";
if(!isset($_COOKIE[$cookiename])) {
echo "Cookie '" . $cookiename . "' isn't set <br>";
} else {
echo "Cookie '" . $cookiename . "' is set <br>";
echo "Value: " . $_COOKIE[$cookiename];
}
?>
<script>
function getCookie(UID) {
var name = UID + "=";
var decodedCookie = decodeURIComponent(document.cookie);
var ca = decodedCookie.split(';');
for(var i = 0; i <ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
function getCode(){
var uid = getCookie("UID");
if (uid == "") {
return;
console.log("empty");
} else {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("divCode").innerHTML = this.responseText;
console.log("on ready");
}
};
xmlhttp.open("GET","getCode.php?q="+uid,true);
console.log("open");
xmlhttp.send();
console.log("send");
}
}
</script>
转到服务器上的php文件以处理获取请求:
$q = intval($_GET['q']);
echo "$q";
$servername = "localhost";
$username = "user";
$password = "password";
$dbname = "dbname";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
if (!$conn) {
die('can't connect: ' . mysqli_error($conn));
}
mysqli_select_db($conn,"table");
$sql="SELECT code FROM table WHERE uid = ".$q;
$result = mysqli_query($conn,$sql);
echo "<table>
<tr>
<th>Code</th>
</tr>";
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['code'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($conn);
答案 0 :(得分:0)
Captive Portal将cookie存储在沙盒环境中,它无法与android和ios中的普通浏览器共享。