<?
$DB_SERVER = "server"; /* nama host server basis data */
$DB_NAME = "namadb"; /* nama basis data */
$DB_USER = "akar"; /* pengguna basis data */
$DB_PASS = "*************"; /* kata sandi basis data */
$DB_SELECT_DB = "";
$SESS_LIFE = get_cfg_var("sesi.gc_maxlifetime");
fungsi sess_open($save_path, $session_name) {
global $DB_SERVER, $DB_NAME, $DB_USER, $DB_PASS, $DB_SELECT_DB;
jika (! $DB_SELECT_DB = mysql_pconnect($DB_SERVER, $DB_USER, $DB_PASS)) {
echo "MAAF! MYSQL ERROR : Tidak dapat terhubung ke $DB_SERVER sebagai $DB_USER";
echo "Kesalahan MySQL:", mysql_error();
mati;
}
jika (! mysql_select_db($DB_NAME, $DB_SELECT_DB)) {
echo "MAAF! MYSQL ERROR : Tidak dapat memilih database $DB_NAME";
mati;
}
mengembalikan nilai benar;
}
fungsi sess_close() {
kembali benar;
}
fungsi sess_read($SessionKey){
global $DB_SELECT_DB, $SESS_LIFE;
$Query = "PILIH SessionArray DARI cdb_global_sessions WHERE SessionKey = '".$SessionKey."' DAN SessionExpTime > " . waktu();
$Hasil = mysql_query($Query, $DB_SELECT_DB);
if (daftar($SessionArray) = mysql_fetch_row($Hasil)) {
kembalikan $SessionArray;
}
kembali salah;
}
fungsi sess_write($SessionKey, $VArray) {
global $DB_SELECT_DB, $SESS_LIFE;
$SessionExpTime = waktu() + $SESS_LIFE;
$SessionArray = menambahkan garis miring($VArray);
$Query = "MASUKKAN KE cdb_global_sessions (SessionKey,SessionExpTime,SessionArray) VALUES ('".$SessionKey."','".$SessionExpTime."','".$SessionArray."')";
$Hasil = mysql_query($Query, $DB_SELECT_DB);
jika (!$Hasil){
$Query = "PERBARUI cdb_global_sessions SET SessionExpTime = '".$SessionExpTime."', SessionArray = '".$SessionArray."' WHERE SessionKey = '".$SessionKey."' DAN SessionExpTime > " . waktu();
$Hasil = mysql_query($Query, $DB_SELECT_DB);
}
kembalikan $Hasil;
}
fungsi sess_destroy($SessionKey) {
global $DB_SELECT_DB;
$Query = "HAPUS DARI cdb_global_sessions WHERE SessionKey = '".$SessionKey."'";
$Hasil = mysql_query($Query, $DB_SELECT_DB);
kembalikan $Hasil;
}
fungsi sess_gc($maxlifetime) {
global $DB_SELECT_DB;
$Query = "HAPUS DARI cdb_global_sessions DI MANA SessionExpTime < " . waktu();
$Hasil = mysql_query($Query, $DB_SELECT_DB);
kembalikan mysql_affected_rows($DB_SELECT_DB);
}
sesi_set_save_handler(
"sess_open",
"sess_dekat",
"sess_baca",
"sess_tulis",
"sess_hancurkan",
"sess_gc");
sesi_mulai();
?>