Kiesyś pisałem własną klase obsługująca sesje wykorzystującą klucz.
http://php.pl/viewtopic.php?t=8234&start=15
Po kazdym klknięciu jest generowany nowy klucz który jest przekazywany wraz z numerem sesji w session_id(). Więc raz kliknięty już nie ozwala na ponowne wykorzystanie i przejęcie sesji.
Może teraz ktoś to zauważy.
Co o tym sądzicie??
[php:1:05ec639f13]<?php
<?php
class session
{
var $sesid;
var $klucz;
var $new_klucz;
function read( $id )
{
$key=$this->decode($id);
if($key==false){
//echo"newkey";
$id=$this->new_sid();
$this->sesid=$id;
$new_id=$this->code($id,$this->gen_klucz());
session_id($new_id);
$key=$this->decode(session_id());
}else{
$this->sesid=$key['0'];
}
$this->klucz=$key['1'];
$this->new_klucz=$this->gen_klucz();
$new_id=$this->code($this->sesid,$this->new_klucz);
session_id($new_id);
$query="SELECT * FROM " . $this->db['ss_table'] . " WHERE " .
$this->db['id_field'] . " = '" . $this->sesid . "' AND " .
$this->db['ex_field'] . " > '" . time() . "' AND
".$this->db['token_table']."='".$this->klucz."'";
$query = mysql_query($query);
if ( mysql_num_rows( $query ) > 0 )
{
$info = mysql_fetch_assoc( $query );
return( $info['DATA'] );
}
else
{
$query="SELECT * FROM " . $this->db['ss_table'] . " WHERE " .
$this->db['id_field'] . " = '" . $this->sesid . "'";
$query = mysql_query($query);
if ( mysql_num_rows( $query ) > 0 )
{
$id=$this->new_sid();
$key=$this->gen_klucz();
$new_id=$this->code($id,$key);
session_id($new_id);
$this->sesid=$id;
$this->new_klucz=$key;
}
return( false );
}
}
function new_sid()
{
$_sid = substr(md5(uniqid(rand(), true)), 0, 32);
return( $_sid );
}
function decode($kod)
{
if (ereg('/^([a-zA-Z0-9]*)$/i', $kod)){
return false;
}
$odk = base64_decode($kod);
$odkodowany=explode("|",$odk);
if(count($odkodowany)!=2){
return false;
}
return $odkodowany;
}
function code($sesid,$klucz)
{
$key[0]=$sesid;
$key[1]=$klucz;
if(!isset($key[0]) && !isset($key[1])){
return false;
}
$zakod=implode("|",$key);
$zakodowany=base64_encode($zakod);
return $zakodowany;
}
function gen_klucz()
{
$klucz = substr(md5(uniqid(rand(), true)), 5, 5);
return $klucz;
}
}
?>
?>[/php:1:05ec639f13]