javascript - Should I put a Google sign in button on every page? -


i have built quite simple site users sign in google sign in button on index page. after verifying token etc, php session created, carrying google user id page page in order identify user.

i wrote bit of code (with intention of including in pages) display google sign-in button, verify token again , exit index.php if google-generated user id doesn't match 1 being carried php session. i'm not sure if necessary, thought might improve security little in case possible spoof session user id.

<div class="g-signin2" data-onsuccess="onsignin"></div> <script> function onsignin(googleuser) {   var profile = googleuser.getbasicprofile();   console.log('id: ' + profile.getid()); // not send backend! use id token instead.    var id_token = googleuser.getauthresponse().id_token;   var userid = <? echo $userid; ?>;    $.get("https://www.googleapis.com/oauth2/v3/tokeninfo?id_token=" + id_token, function( data ) {                if (data.sub != userid)         {             window.location = 'index.php'; // if google log-in doesn't match $userid, redirects index         }     }, "json" );                                                                  }  </script> 

is necessary, or should have sign-in button on front page , rely on session user id on?

i suppose have issue if user bookmarks page, in case maybe better off having sort of check if session has been created , redirecting if not?

use $_session['loggedin'] or similiar.

loggedincheck.php:

<?php  session_start();   if($_session['loggedin']==false){      session_destroy();      header("location: /login.php");      die;  }   else{} 

Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -