HiveBrain v1.2.0
Get Started
← Back to all entries
patternphpMinor

Session in database

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
databasesessionstackoverflow

Problem

I'm posting my PHP code for sessions using MySQL. Please tell me if there are any errors, if it can be optimized, or if security can be enhanced.

  • Host: localhost



  • User: root



  • Password: ""



  • Database: pro



Table structure:


SessionID [pk] - Data - DateTouched

=?");
   mysqli_stmt_bind_param($stmt,"s",$sess_maxlifetime);
   mysqli_stmt_execute($stmt);
   return true;
  }

  session_set_save_handler("open", "close", "read", "write", "destroy", "gc");
  session_name('Session');
  session_start();
 ?>

Solution

Your open and close functions don't do anything. You could use them to connect & disconnect from the database. That way, an error in the connection won't be a read or write error, but will be an error in open. That may later help diagnosing such errors. It also means less duplicated code and it may mean fewer connections to the database (which might speed up things a bit).

Context

StackExchange Code Review Q#2310, answer score: 2

Revisions (0)

No revisions yet.