php security for cookies and sessions -


regarding php security cookies , sessions, have done far prevention of attacks. have done incorrectly/unsafely?

login.php

 if ($username==$dbusername&&$hashed_password==$dbpassword){  setcookie('username[0]',$username,time()+(60*60*24*365)); setcookie('username[1]',$userid,time()+(60*60*24*365)); setcookie('password',$hashed_password,time()+(60*60*24*365));  if($admin=='1') { setcookie('username[3]',$admin,time()+(60*60*24*365));   } $_session['logged-in']=1; 

logout.php

    $time = time()-(60*60*24*365); setcookie('username[0]', '',$time); setcookie('username[1]', '',$time); setcookie('username[2]', '',$time); setcookie('username[3]', '',$time); setcookie('password', '',$time); unset($_cookie['username']);  unset($_session['logged-in']); 

i call session_regenerate_id() on everypage, correct stop session fixation/hijacking?

<?php session_start(); session_regenerate_id(); 

here php.ini other ways provide security sessions & cookies

    session.use_trans_sid = 0 session.user_only_cookies = 1 

any examples/impovements welcomed, learn better examples.

often regenerating session-id done, when changing access priviledges (e.g. after login).

the password should not stored in cookie on client side, not hash. it's not necessary store in session, use verify login, , after writing state session, should forget password.

if want safe site, need https connection ssl encryption. otherwise attacker can eavesdrop information sent plaintext, , use session-id (or whatever use authenticate user) impersonate user.


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -