<?
function sess_open($sess_path, $session_name){
global $_SEC_SESSION;
$sess_sec=ini_get('session.name')."_sec";
# Apart from the session cookie we set another one, with the same name plus
# '_sec' at the end
# On that cookie, we set a random 32byte string (I'll refer to this string
# as 'key')
if (!isset($_COOKIE[$sess_sec])){
$md5=md5(uniqid(''));
setcookie($sess_sec,$md5,ini_get('session.cookie_l ifetime'),ini_get('session.cookie_path'),ini_get(' session.cookie_domain'));
$_SEC_SESSION['int']['key']=$_COOKIE[$sess_sec]=$md5;
$_SEC_SESSION['data']=serialize(array());
$empty=1;
}else{
$_SEC_SESSION['int']['key']=$md5=$_COOKIE[$sess_sec];
}
# The name of the file that contains the session info,
# starts with 'sec_sess_' and it's followed by the md5 string of the
# session_id concatenated with the previous key.
# This avoids people of reading the ID of the session from the session files
# (to hijack the session)
$_SEC_SESSION['int']['filename']=$filename_sec="$sess_path/sec_sess_".md5(session_id().$md5);
if (isset($empty)){
return 1;
}
if (!file_exists($filename_sec)){
fclose(fopen($filename_sec,'w'));
}
if (!$_SEC_SESSION['int']['fd']=fopen($filename_sec,'r')){
$_SEC_SESSION['data']=serialize(array());
return 0;
}
# The data on that file is dedrypted using the previous key
$data_enc=fread($_SEC_SESSION['int']['fd'],filesize($filename_sec));
fclose($_SEC_SESSION['int']['fd']);
if ($data_enc!=''){
$cipher=MCRYPT_DES;
$data=@mcrypt_ecb($cipher,$_SEC_SESSION['int']['key'],$data_enc,MCRYPT_DECRYPT);
}else{$data='';}
$_SEC_SESSION['data']=$data;
$_SEC_SESSION['int']['hash']=md5($_SEC_SESSION['data']);
return 1;
}
function sess_close(){
return true;
}
function sess_read($key){
return $GLOBALS['_SEC_SESSION']['data'];
}
function sess_write($id,$data){
global $_SEC_SESSION;
$sd=$data;
if ($_SEC_SESSION['int']['hash'] != md5($sd)){
$fd=fopen($_SEC_SESSION['int']['filename'],'w');
$cipher=MCRYPT_DES;
# Here we crypt the data with our key...
$data=@mcrypt_ecb($cipher,$_SEC_SESSION['int']['key'],$sd,MCRYPT_ENCRYPT);
fputs($fd,$data);
fclose($fd);
chmod($_SEC_SESSION['int']['filename'],0600);
}
}
function sess_destroy($key){
return(@unlink($GLOBALS['_SEC_SESSION']['int']['filename']));
}
function sess_gc($maxlifetime){}
session_set_save_handler('sess_open','sess_close', 'sess_read','sess_write','sess_destroy','sess_gc') ;
session_start();
if (!isset($_SESSION['times'])){
$_SESSION['times']=0;
}
$_SESSION['times']++;
print "This session ID is: ".session_id()." but the name of the file that contains the data is ".$_SEC_SESSION['int']['filename']."<br />\n";
print "Btw, this is the ".$_SESSION['times']." you see this page ;) (it works!)<Br />\n";
?>
El Problema es el siguiente.
1. Cuando ingresas la primera vez, me tira un file (ejemplo):
This session ID is: 5028c50a914dc7d7851b8a109b81443f but the name of the file that contains the data is /tmp/sec_sess_f03775b8231a6393dfa134685d0ab78b
Btw, this is the 1 you see this page ;) (it works!)
--------------------------------------------------------------------------------------
2. Y cuando hago refresh me tira unos errores y me cambia el file, y de esta manera las variables que registre la primera vez que entre al sitio, las pierdo. El error es el siguiente:
Warning: fread(): Length parameter must be greater than 0. in /home/www/discountpharmacyusa/demo/index.php on line 116
Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /home/www/discountpharmacyusa/demo/index.php:116) in /home/www/discountpharmacyusa/demo/index.php on line 154
Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/www/discountpharmacyusa/demo/index.php:116) in /home/www/discountpharmacyusa/demo/index.php on line 154
This session ID is: 5028c50a914dc7d7851b8a109b81443f but the name of the file that contains the data is /tmp/sec_sess_ea256c9fa1e2ca28f3aad452df7958a8
Btw, this is the 1 you see this page ;) (it works!)
--------------------------------------------------------------------------------------
3. El error principal es el del fread() y desp. se originan los otros a causa del mismo, ahora no se si fread() tira el error porque no encontro el archivo a leer, o porke no contiene nada entonces al ser filesize<=0 tira el error. Este error lo consegui obviar con la siguiente linea, ke la coloke donde esta el fread() original del script ke esta arriba:
<?
$data_enc=fread($_SEC_SESSION['int']['fd'],(filesize($filename_sec)>0?filesize($filename_sec ):1));
?>
--------------------------------------------------------------------------------------
El error de fread(), con esa linea lo esquiva, pero me sigue cambiando el nombre del FILE original de cuando entras por primera vez al sitio, y de esta manera las variables ke seteo ni bien entro al sitio mio, las pierdo.
Ojo, una vez ke se cambia el FILE, desp, el sitio y el sistema este de "Sesiones Seguras", funciona joya, pero vuelvo a repetir que el FILE no es el mismo ke cuando entre la primera vez.
Se entendio ?? perdon por el gran mensaje.
Saben que puede ser?? me ta volviendo loko, porque se que debe ser una boludez proveniente de mi ignorancia sobre PHP. jeje
![lloron](http://static.forosdelweb.com/fdwtheme/images/smilies/chillando.png)
Si no conocian el script, espero les sirva.
Agredeceria me den una mano, no entendo mucho de prog. pero si de diseño, cualquier cosa ke pueda ayudarlos, lo hare con placer.
saludos
![Adios](http://static.forosdelweb.com/fdwtheme/images/smilies/adios.gif)
![Adios](http://static.forosdelweb.com/fdwtheme/images/smilies/adios.gif)
![Adios](http://static.forosdelweb.com/fdwtheme/images/smilies/adios.gif)