dongli5785 2013-12-22 07: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 08: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条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部