我创建会话时,单击它的每个链接都会启动。
但是会话只能启动令牌代码
当我单击每个链接时,我想进行一次令牌会话
例如
<a href="member.php?token=4r5tfgbvf&id=1" target="_blank">Click me1</a><br>
<a href="member.php?token=fgvbhnj&id=2" target="_blank">Click me2</a><br>
当我点击“ click me2”,然后创建会话
<?php
$_SESSION['token'] = "fgvbhnj";<br>
?>
.member{
padding:5px 5px;
background:#e7f9eb;
overflow:auto;
}
.memo {
float:left;width:242px;
margin:5px;
padding:5px 5px;
background:#fff;
}
<div class="member">
<?php
for( $i1 = 0; $i1 <= 5; $i1++ ) {
for ($s = '', $i = 0, $z = strlen($a = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-=#$@!^&')-1; $i != 10; $x = rand(0,$z), $s .= $a{$x}, $i++);
?>
<a href="membershow.php?token=<?php echo $s; ?>&id=<?php echo $i1; ?>" target="_target">
<div class="memo">
<?php echo $i1; ?>
</div>
</a>
<?php
}
?>
</div>
答案 0 :(得分:-1)
您可以将数据存储在cookie中并检索数据。您可以创建如下所示的Cookie-
function writeCookie(name,value,days) {
var date, expires;
if (days) {
date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
expires = "; expires=" + date.toGMTString();
}else{
expires = "";
}
document.cookie = name + "=" + value + expires + "; path=/";
}
然后在每个页面中需要此会话ID,您可以使用以下功能读取cookie:
function readCookie(name) {
var i, c, ca, nameEQ = name + "=";
ca = document.cookie.split(';');
for(i=0;i < ca.length;i++) {
c = ca[i];
while (c.charAt(0)==' ') {
c = c.substring(1,c.length);
}
if (c.indexOf(nameEQ) == 0) {
return c.substring(nameEQ.length,c.length);
}
}
return '';
}
读取功能可从编写该功能的同一域的任何页面或标签中进行,无论该Cookie是通过javascript中的页面还是通过服务器创建的。 要将ID存储在cookie中-
var sId = 's234543245';
writeCookie('sessionId', sId, 3);
要读取cookie-
var sId = readCookie('sessionId')