简体   繁体   中英

opencart track session id

I have the following index.php file in the root folder. The actual website is in the subdirectory and gets accessed after the user logs in. My problem is when the user closes the tab, but not the browser, then the session isnt terminated.

When they go back to the site, it asks them to log in, but they are already logged in so the login feature doesnt work and wont redirect them to the actual site. I see that the sessionid is being tracked by the browser. I am fairly new to web development.

How would I check to see if a session has been recorded and if so redirect to a different URL? Thank you

Here is the script part of it, the rest is just html, text fields etc to get the login page to look nice, and to accept user info.

<script type="text/javascript"><!--
$('#button-cart').on('click', function() {
    $.ajax({
        url: 'login/index.php?route=account/loginajax',
        type: 'post',
        data: $('input[type=\'text\'], input[type=\'password\']'),
        dataType: 'json',
        beforeSend: function() {
            $('#button-cart').button('loading');
        },
        complete: function() {
            $('#button-cart').button('reset');
        },
        success: function(json) {
            $('.alert, .text-danger').remove();
            $('.form-group').removeClass('has-error');
            if (json['error']) {
                $('.error').after('<div class="alert alert-danger has-error">' + json['error'] + '</div>');
            }
            if (json['success']) {
                $('.error').after('<div class="alert alert-success">' + json['success'] + '</div>');
                window.location = "http://www.mbdtesting.com/login/index.php?     route=account/account";
            }
        }
    });
});
</script>

Try to put something like this on the top of every web page you have

<? php
session_start();
if (isset($_SESSION['admin_id'])) {
  header("location: home.php");//the path or url of the page you want the client to be redirected if the session is set.
  exit();
} 
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM