Reputation: 2287
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.
Upvotes: 0
Views: 113
Reputation:
write unset($_SESSION['arraystuff']);
or
session_unset();
session_destroy();
at the end where ur sending mail..write it unser email success msg/varible..
Upvotes: 3
Reputation: 172
Make sure that you are starting the session also on page 3. Secondly try the following to empty your session.
unset($_SESSION);
Upvotes: 1