0

我有一个简单的 jQuery 函数,并且在某个时刻(假设单击按钮)我想启动一个 PHP 会话。

    $(document).ready(function() {
        $(".loginPopupButton").click(function(){
            //here I'd need a way to trigger the session.
        });
    });

我假设从 PHP 启动会话可以像更改 PHP 变量一样容易。例如 - PHP 可以是这样的:

    <?php
        $testVar = null;
        if(isset($testVar)){
            session_start()
            $_SESSION['sessionStarted'] = $testVar;
        }

    ?>

有没有办法启动这样的会话?

4

1 回答 1

0
   <?php
    session_start();

    if(isset($_GET['login'])) { 
        if(isset($_SESSION['sessionStarted'])) {
            echo 'session is already set';
        } else {
            $_SESSION['sessionStarted'] = $testVar;
        }
    }
    ?>

and client-side:

$(document).ready(function() {
    $(".loginPopupButton").click(function(){
        //code to redirect to index.php?login=true or make some ajax GET call, doesnt matter
    });
});

then you can add like php checks, if session exists, do not echo loginPopupButton and so on :)

于 2013-07-15T08:36:19.420 回答