1

I'd like to build a site that has only HTML/jQuery in the frontend and PHP/MySQL in the backend.

How can I manage the user sessions (login/logout) and work with session variables using only HTML/jQuery?

Thanks

vittochan
  • 635
  • 1
  • 7
  • 18

1 Answers1

0

Using jQuery you could perform AJAX calls to a page in php with method to login, logout and query for session variables.

Also. If your app is not working with server at regultar intervals make request to server to keep session alive.

Login example

JQuery

$.ajax({
  dataType: "json",
  url: "http://yoursite.com/ajax.php?method=login",
  data: yourloginData,
  success: yourSuccesAction
});

PHP

<?php
if(isset($_GET['method']){
    if ($_GET['method'] == 'login'){
      // do login here and print response to server 
      // for example in json with json_encode
    }
}

More information see:

Demo: jQuery Ajax Call to PHP Script with JSON Return

jQuery ajax request with json response, how to?

Community
  • 1
  • 1
Dubas
  • 2,855
  • 1
  • 25
  • 37