473,811 Members | 3,686 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 1398

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

Similar topics

2
2821
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 fully, then please send those links this way! I'm particularly interested in the...
1
1794
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 of what the problem is.
9
2649
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
2095
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 don't fully understand how sessions work. This that I'm using came from a book by Larry Ullman (chapter...
0
9726
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9605
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10647
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10395
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
10130
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7667
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6887
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3865
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3017
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.