简体   繁体   中英

Set a session variable on button click

I'm using the google php api and when I click a button I want to set a session variable so for example I have the following button

<button type="button" class="btn btn-gmail g-signin" id="signinButton" 
data-scope="https://www.googleapis.com/auth/plus.login"
data-clientid="XXXX"
data-redirecturi="postmessage"
data-accesstype="offline"
data-cookiepolicy="single_host_origin"
include_granted_scopes="true"
data-callback="signInCallback">
signin</button>

When this button is clicked it calls the signIncallback now I also want it to set a session variable that I can later use to identify what button was clicked so on button click

$_SESSION['button'] = 'signin';

how would I achieve this or is there an easier way in which I could pass the button id to signInCallback?

With the suggestions given here I was able to find an answer to my problem.

When I click a button the following code is called

$('#signinButton').on('click', function(e){
    var name = $(this).attr('name');
    $.ajax({
        type: 'POST',
        url: 'scripts/service.php',
        data: {
            service: name
        }
    }); 
});

then the following code in the service.php file

<?php
    session_start();
    $_SESSION['service'] = $_POST['service'];
?>

您可以将Ajax请求发送到将要安装会话的页面,然后重定向回

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM