【问题标题】:php 5 variable from javascript not unset来自javascript的php 5变量未设置
【发布时间】:2012-11-05 05:14:57
【问题描述】:

注意:单击http://communitychessclub.com/rabren/index.php?clear=1 的左侧棋子应该会取消设置 $choice 并重新加载页面。但它只是重新加载页面。

我想检查在 javascript 中设置的变量状态。

 onclick="window.location='index.php?clear=1'

if clear == "1" 我想用:

重置$choice_1
if ($_GET['clear']=="1") {empty($_SESSION['choice_1']);}

并重建数组并生成新的图像引用。

但我所拥有的不起作用;它永远不会重置或清空$choice_1

我有一张带有主页链接的图片:

<img onclick="window.location='index.php?clear=1'; return false;" 
src="images/WL<?php echo $_SESSION['choice_1'];?>.png" alt="pieces" width=128 height=128>

我在 index.php 的顶部:

图像集:

<?php 

if ($_GET['clear']=="1") {empty($_SESSION['choice_1']);}

if(!isset($_SESSION['choice_1'])) {
$chessmen = array("N","Q","R","B","K","P"); 

$random_piece = array_rand($chessmen); 
$_SESSION['choice_1'] = $chessmen[$random_piece];

unset($chessmen[$random_piece]);

$random_piece = array_rand($chessmen); 
$_SESSION['choice_2'] = $chessmen[$random_piece];
} 
?>

【问题讨论】:

    标签: php unset


    【解决方案1】:

    Empty只判断一个变量是否为空,使用unset。

    if ($_GET['clear']=="1") {unset($_SESSION['choice_1']);}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-04-12
      • 2023-03-24
      • 2012-04-11
      • 2019-07-25
      • 2018-05-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多