Foros del Web » Programando para Internet » PHP »

sesiones seguras

Estas en el tema de sesiones seguras en el foro de PHP en Foros del Web. hola, queria preguntarles como puedo hacer una sesion segura y que ninguna persona ajena tenga acceso a ellas. cuando hago el logeo del usuario, guarda ...
  #1 (permalink)  
Antiguo 17/02/2007, 10:00
 
Fecha de Ingreso: diciembre-2006
Mensajes: 381
Antigüedad: 17 años, 4 meses
Puntos: 2
sesiones seguras

hola, queria preguntarles como puedo hacer una sesion segura y que ninguna persona ajena tenga acceso a ellas.

cuando hago el logeo del usuario, guarda en sesiones sus datos para mostrarlos en las demas paginas.

Código PHP:
$_SESSION['clie_nomb']=$fields["clie_nomb"];
$_SESSION['clie_dire']=$fields["clie_dire"];
$_SESSION['clie_ruc']=$fields["clie_ruec"]; 

Pero hay una forma mas segura de hacer eso?

dicen que hay personas que tienen acceso a las sesiones mediante el ID de sesion.

Pueden ayudarme?

pd: ya falta poco para terminar mi proyecto.
  #2 (permalink)  
Antiguo 17/02/2007, 10:44
Avatar de locojars  
Fecha de Ingreso: mayo-2002
Mensajes: 265
Antigüedad: 22 años
Puntos: 4
Re: sesiones seguras

Quiza si codificas tu session te resulte mas seguro, aquí te dejo un link dond ehay una clase que te puede ayudar a hacer esto:
http://www.phpclasses.org/browse/package/3694.html

Espero te sirva.
Salu2,
Jars.
__________________
No le digas a Jehová que tan grande es tu problema, dile a tu problema cuan grande es Jehová.
  #3 (permalink)  
Antiguo 17/02/2007, 10:58
 
Fecha de Ingreso: diciembre-2006
Mensajes: 381
Antigüedad: 17 años, 4 meses
Puntos: 2
Re: sesiones seguras

Gracias por la info, pero para descargar el archivo me pide registrarme, bueno tendre que hacerlo, aunque tambien encontre un codigo en google:

Código PHP:
<?php
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_lifetime'),
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;
session)
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
$_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']."n";

print 
"Btw, this is the ".$_SESSION['times']." you see this page ;) (it works!)n";
?>
Sinceramente no entiendo este codigo
Aun me falta aprender mas.
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 00:51.