dongli5785 2013-12-22 15:56
浏览 37
已采纳

在回声中取消设置会话导致问题

I am getting the following error and can not figure out why. I've been staring at this for too long..

Error:

Parse error: syntax error, unexpected T_UNSET in blah/blah/blah

My code:

Essentially, I am trying to give the user the ability to clear a session via clicking a link. Not sure where I am going wrong within my syntax... Any help would be much appreciated!

NOTE: Yes, my code is within php blocks

echo "<span><a href='" . unset($_SESSION['vertical']) . "'>clear "
 . $vertical . "</a></span>";

Thanks in advance!

  • 写回答

3条回答 默认 最新

  • double2022 2013-12-22 16:08
    关注

    You cannot call PHP functions after the page has finished loading. PHP is a server-side technology and works on the server, not on the client's computer. Which means, you won't be able to call a PHP function without sending the details to the script.

    If you're trying to trigger the unset function when the user clicks the link, then you could create a link to a script where you unset the $_SESSION variable:

    <span><a href='somepage.php?somevar=42'>foo</a></span>
    

    When the user clicks on the link, they'll be taken to somepage.php. Now, you can check if the somevar key is set and then unset the session in the script:

    <?php
    session_start();
    
    if (isset($_GET['somevar'])) {
        unset($_SESSION['vertical']);
    }
    

    If you want to do this without a page refresh, then you might want to take a look at AJAX.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 shape_predictor_68_face_landmarks.dat
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料