PHP Classes

Store custom data by using sessions

Recommend this page to a friend!

      PHP OAuth Library  >  PHP OAuth Library package blog  >  Learn with a PHP OAut...  >  All threads  >  Store custom data by using sessions  >  (Un) Subscribe thread alerts  
Subject:Store custom data by using sessions
Summary:Store custom data by using sessions
Messages:3
Author:Vincent
Date:2016-02-13 19:24:13
 

  1. Store custom data by using sessions   Reply   Report abuse  
Picture of Vincent Vincent - 2016-02-13 19:24:13
Hi,

I need some advice on handling data before and after getting OAuth credentials from Twitter. I'd like to store OAuth credentials in a MySQL database. I'm using mysqli_login_with_twitter.php. This works excellent when setting a fixed number for users ($client->SetUser(1)). I wish to set the user ID manually.

My web application works as follows:
Users login on my application. After login, the application searches the database for the user ID. This ID should be temporary stored for use after Twitter authentication. When there are no Twitter OAuth settings available, the user is sent to Twitter to connect. After the user accepts the connection, Twitter sends the user back to my application. From that moment I need the user ID to set in $client->SetUser(###).

I tried using $_SESSION without any result. It seems all sessions are destroyed when the user returns.

Can you give me some advice how to store the user ID?

Thank you in advance for your response.

  2. Re: Store custom data by using sessions   Reply   Report abuse  
Picture of Vincent Vincent - 2016-02-13 19:32:09 - In reply to message 1 from Vincent
Sorry, for my question. I solved my problem. ;)

  3. Re: Store custom data by using sessions   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2016-02-13 20:42:00 - In reply to message 1 from Vincent
The user ID should be determined by your application somehow by looking at the Twitter user details and querying your database to see what user owns that account.

You probably should have a table that relates user ID with Twitter account users. You look at this table for the Twitter account user. If it exists, retrieve your user ID and pass to that function. If it does not exist, create one record to associate a new user ID with the Twitter account.