0

I have an array within a PHP Session variable which I need to remove via AJAX.

This is how I do it:

  1. HTML:

    <a href="#" onclick="delete_pix(false, '1', false, '1.jpg');">remove</a>`
    
  2. JavaScript:

    function delete_pix(id, no, hash, plupload){
    $.post("/remove.php",{ 
        id: id, 
        no: no, 
        h: hash, 
        pl: plupload
    }); 
    }
    
  3. remove.php

    unset($_SESSION['files']);
    error_log(print_r($_SESSION, 1).'test');
    

Unfortunately this does not work. The file remove.php does not have access to the session. print_r($_SESSION) does not output any values.

Thank you in advance on any help on this.

6
  • 1
    are you saying that you want to remove 'superglobal', or automatic global, variable. ? php.net/manual/en/reserved.variables.session.php Commented Mar 14, 2016 at 15:48
  • 4
    Looks like you just forgot session_start Commented Mar 14, 2016 at 15:49
  • @llamerr — Looks more like a value in the session array, not the array itself. Commented Mar 14, 2016 at 15:49
  • php.net/manual/en/function.error-reporting.php and look at your console. Commented Mar 14, 2016 at 15:51
  • To answer this question you need to post what $_SESSION['files'] looks like before. Also, as Quentin pointed out, you need session_start(). Commented Mar 14, 2016 at 15:52

1 Answer 1

1

In your funtion on php you need call the method session_start(); and later session_unset($_SESSION['nameOfSession']); this will erase your session.

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

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.