473,578 Members | 2,778 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_sav e_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_n ame;

$sess_save_path = $save_path;
$sess_session_n ame = $session_name;
return(true);
}

function close() {
return(true);
}

function read ($id) {
global $sess_save_path , $sess_session_n ame;

$sess_file = "$sess_save_pat h/$id/sess_$id";

if ($fp = @fopen($sess_fi le, "r")) {
$sess_data = fread($fp, filesize($sess_ file));
return($sess_da ta);
} else {
return(""); // Doit retourner "" ici.
}

}

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

if ( ! is_dir("$sess_s ave_path/$id") ) {
mkdir("$sess_sa ve_path/$id");
}
$sess_file = "$sess_save_pat h/$id/sess_$id";

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

}

function destroy ($id) {
global $sess_save_path , $sess_session_n ame;

$sess_file = "$sess_save_pat h/$id/sess_$id";

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

return(@unlink( $sess_file));
}

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

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

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

Similar topics

2
2807
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 information between pages, which I knew already. I want to know HOW sessions work! If anybody has any good links to material that explains sessions...
1
1784
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 changing my subject line in order to avoid confusion. I was asked to provide a code example for analysis, so here it is, along with a a description...
9
2632
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'; global $LOGINDIR;
5
2084
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 post a resume in order to respond to certain ads. The employers and the job seekers register their information into their own database table. I...
0
8126
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8291
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7874
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8150
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5664
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 presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3786
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3801
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2293
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 we have to send another system
0
1114
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.