0

I have 3 pages;

Page 1: Main page that has an AJAX file uploader

Page 2: (AJAX request from page 1) Handles the file uploader, starts a session and stores the filename in the session, if more than 1 file is uploaded this page gets called more then once.

Page 3: (AJAX request from page 1) when page 2 uploads all files, page 1 sends a request to this page, so that this page sends an email with the 2 filenames stored in the session, an after that it tries to clear the whole session, so that it's ready for any new uploads on page refresh of page 1.

Now the problem I'm facing, is that in page 3 the sessions aren't getting cleared, so everytime I'm getting a session array twice as big, because it has before's filenames, and the filenames that were just put in there now.

Here is the code I'm using:

Page 1: Normal JS & Ajax requests

Page 2:

This one actually sets the array inside the session

session_start();
send_nosniff_header();
nocache_headers();
//BLA BLA BLA - here is where the actual file uploader code is suppose to be

//Here is the session im setting and storing
if (!isset($_SESSION['arraystuff'])) {
$_SESSION['arraystuff'] = array();
}
$_SESSION['arraystuff'][] =  $uploads_dir.'/'.$filename;

Page 3:

This one sends an email with every filename stored inside the session

if(isset($_GET['uploadComplete'])){
session_start();
//Get foreach filenames inside session and send email
$_SESSION = array();
session_destroy(); 
}

Yet session is not cleared for next one to work properly, as each time the email is sent, the previous filenames from the session before are sent aswell and not cleared.

1
  • maybe you should make the AJAX call synchronous? also what would happen if the call was from several clientS? Commented Sep 3, 2013 at 8:06

2 Answers 2

3

write unset($_SESSION['arraystuff']); or

session_unset();
session_destroy();

at the end where ur sending mail..write it unser email success msg/varible..

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

2 Comments

I just did, and whenever I refresh the page and submit everything again, the session from before is still there, and the new data gets added to the old and when an email is sent the old and new filenames are sent with it..
I added a session_start and session_destroy and unset to page 1, and it seems that it did the trick
1

Make sure that you are starting the session also on page 3. Secondly try the following to empty your session.

unset($_SESSION);

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.