Reputation: 380
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?
Upvotes: 0
Views: 10169
Reputation: 380
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'];
?>
Upvotes: 1
Reputation: 16
You can just send Ajax request to the page where it will be installed session, and then redirect back
Upvotes: 0