473,498 Members | 1,832 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

sessions gc and destroy

Hi everybody,
I am making a small site. This site uses sessions and I need to store
pictures for each session. I solved this problem thanks to the
session_set_save_handler() function. Sessions have their own folder
where all files are stored. It works quite well for the open, read and
write processes. You can find how I changed the sessions management.
But I don't know what to do at the end of a session. I know that I have
to make something with the "gc" and "destroy" functions but I don't know
what. The session ends when the browser is closed, but the files are not
deleted. What should I do ? Can someone help me to write the gc() and
destroy() functions.
Thanks in advance.

<?php
function open ($save_path, $session_name) {
global $sess_save_path, $sess_session_name;

$sess_save_path = $save_path;
$sess_session_name = $session_name;
return(true);
}

function close() {
return(true);
}

function read ($id) {
global $sess_save_path, $sess_session_name;

$sess_file = "$sess_save_path/$id/sess_$id";

if ($fp = @fopen($sess_file, "r")) {
$sess_data = fread($fp, filesize($sess_file));
return($sess_data);
} else {
return(""); // Doit retourner "" ici.
}

}

function write ($id, $sess_data) {
global $sess_save_path, $sess_session_name;

if ( ! is_dir("$sess_save_path/$id") ) {
mkdir("$sess_save_path/$id");
}
$sess_file = "$sess_save_path/$id/sess_$id";

if ($fp = @fopen($sess_file, "w")) {
return(fwrite($fp, $sess_data));
} else {
return(false);
}

}

function destroy ($id) {
global $sess_save_path, $sess_session_name;

$sess_file = "$sess_save_path/$id/sess_$id";

if ($handle = opendir($sess_save_path)) {
/* Ceci est la façon correcte de traverser un dossier. */
while (false !== ($file = readdir($handle))) {
if ( $file !== "." and $file !== ".." ) {
@unlink($file);
}
}
closedir($handle);
}

return(@unlink($sess_file));
}

/************************************************** *****
* ATTENTION - Vous devrez implémenter un *
* collecteur de données obosolètes ici. *
************************************************** *****/
function gc ($maxlifetime) {
return true;
}

session_set_save_handler ("open", "close", "read", "write", "destroy",
"gc");
?>
Jul 17 '05 #1
0 1375

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2799
by: The Plankmeister | last post by:
Hi... I'm trying my hardest to understand fully how sessions work and how best to use them. However, all I can find is information that doesn't tell me anything other than that sessions store...
1
1778
by: Mountain Man | last post by:
Hi, I posted on this matter earlier with the subject line "Trouble with sessions," but someone else started a different thread with the same subject line that arrived before my post, so I'm...
9
2620
by: Bartosz Wegrzyn | last post by:
I need help with sessions. I createt set of web site for nav with authorization. first I go into main.php which looks like this: <?php //common functions include_once '../login/common.php';...
5
2079
by: DavidPr | last post by:
I'm using sessions now but I've just realized a potential problem. It's a small job board and the employers have to register and login to post ads, and the job seekers have to register, login and...
0
7121
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6993
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7162
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7197
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7375
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4899
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
1411
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
650
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
287
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.