使用AJAX的PHP会话

I'm trying to create an interactive web shell that will let you connect and perform actions in a different website using post requests but I also want the shell to update live (this is the "interactive" part).

I came across Keeping session alive with Curl and PHP and W3School PHP & AJAX but can I blend them together? is it possible to maintain a session with ajax? if not, what should I use to do this project?

EDIT:

To make things more clear, What I'm trying to do is:

  1. Go to my website
  2. Put my credentials to google and click a button
  3. background php sends a post request to google's login page with my credentials
  4. I see in my website a Login succeeded alert using ajax
  5. click a button on my website that will retrieve the content of the first email in my mail dir
  6. send a get request to gmail with php and return the data with ajax

Will it work? In 6 I need a live session to view the page and I'm creating the session on step 3, How do I keep the session alive?