Search code examples
phpgoogle-api-php-clientgoogle-client

Is it safe and norm to put Google_client object in session?


Is it safe to create google_client object and store it in $_SESSION variable.

Can we then use same google_client object from $_SESSION variable on multiple pages to do google stuff. Or, do I have to make new client on every page?

Most of the tutorial or example on internet use only one page, how to use google_client on multiple pages is what I trying to figure?


Solution

  • Keep creating it, but all the auth process and rest of the CLIENT_ID and other important information can be stored in variables for future use. Just instance it every page, re-auth with refresh token with every page change and you're good to go. Also you could do a specific GoogleConnection.php header kind of style and stop worrying of having it to type it every time you add a new page.