Jump to content
Larry Ullman's Book Forums

Ch 12 'Improving Session Security'


Recommended Posts

I understand why one would use the ($_SESSION['agent']), what I would like to ask though is 

 

why , in the conditional 

 

<?

 

 

if (!isset($_SESSION['agent']) OR ($_SESSION['agent'] != md5($_SERVER['HTTP_USER_AGENT']) )) {
 

?>

 

you would use OR and not AND. I would think that you would check for both?

Link to comment
Share on other sites

That code is looking for a point of failure, so either condition being false is sufficient. If the conditional was confirming success, it would be

if (isset($_SESSION['agent']) AND ($_SESSION['agent'] === md5($_SERVER['HTTP_USER_AGENT']) )) {

Notice three changes required:

  • Removal of ! in the first condition
  • Use of AND instead of OR
  • Change of != to === in the second condition
  • Upvote 1
Link to comment
Share on other sites

 Share

×
×
  • Create New...