1

I would like it so that when someone presses a certain link that by using ajax it will run a php file to destroy a session and when its a success the current page will remove an item from Local Storage and then the page will redirect to the index page.

currently have the following but it doesn't work

JQUERY

$('#key a').click(function(e) {
                e.preventDefault();
                $.ajax({
                    type:"POST",
                    url:"/assets/inc/sign-out.php",
                    data:'',
                    dataType:'html',
                    context:document.body,
                    global:false,
                    async:false,
                    success:function(data){
                        console.log(data);
                        localStorage.removeItem("logged");
                        window.location.replace('/');
                    }
                });
            });

PHP

<?php 
include('config.php');
session_destroy();
?>
10
  • 5
    I'm not sure about the content of config.php but there should be a session_start() before session_destroy() Commented Aug 30, 2012 at 12:55
  • any error output? or does that success handler fire up correctly? did you try adding an error() function? Commented Aug 30, 2012 at 12:55
  • 2
    What have you done to try and debug this error? Commented Aug 30, 2012 at 12:56
  • 1
    @Adnan session.auto_start is a php.ini directive Commented Aug 30, 2012 at 12:57
  • 1
    @DonaldSutherland there is nothing in console.log because php doesn't return anything. If you know directly the name of the stored session key you can try unset() it. Commented Aug 30, 2012 at 12:59

2 Answers 2

1

Try

<?php
// include 'config.php'; - does this config.php contain session related configuration like e.g. the cookie-name?

session_start(); // fetch/re-start current session
session_regenerate_id(true); // assign a new session id and delete old data
$_SESSION=array(); // empty session data
session_write_close(); // superfluous call ;-)

as your php script.

see http://docs.php.net/session_regenerate_id

Sign up to request clarification or add additional context in comments.

Comments

0

try this in your php:

session_start();
session_unset(); 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.