<div dir="ltr">Hola Leo, estoy probando el ejemplo del manejador de sesiones con mysql. El código del manual es el siguiente:<div><br></div><div><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px"><?php<br>
</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">class </span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">Session<br>
</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">{<br><br> </span><span class="" style="color:rgb(128,128,128);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">/**<br>
* a database connection resource<br> * @var resource<br> */<br> </span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">private </span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">$_sess_db</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">;<br>
<br> </span><span class="" style="color:rgb(128,128,128);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">/**<br> * Open the session<br>
* @return bool<br> */<br> </span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">public function </span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">open</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">() {<br>
<br> if (</span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">$this</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">-></span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">_sess_db </span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">= </span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">mysql_connect</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">(</span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">SESSION_DB_HOST</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">,<br>
</span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">SESSION_DB_USER</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">,<br>
</span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">SESSION_DB_PASS</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">)) {<br>
return </span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">mysql_select_db</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">(</span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">SESSION_DB_DATABASE</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">, </span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">$this</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">-></span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">_sess_db</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">);<br>
}<br> return </span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">false</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">;<br>
<br> }<br><br> </span><span class="" style="color:rgb(128,128,128);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">/**<br> * Close the session<br>
* @return bool<br> */<br> </span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">public function </span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">close</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">() {<br>
<br> return </span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">mysql_close</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">(</span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">$this</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">-></span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">_sess_db</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">);<br>
<br> }<br><br> </span><span class="" style="color:rgb(128,128,128);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">/**<br> * Close the session<br>
* @return bool<br> */<br> </span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">public function </span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">close</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">() {<br>
<br> return </span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">mysql_close</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">(</span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">$this</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">-></span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">_sess_db</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">);<br>
<br> }<br><br> </span><span class="" style="color:rgb(128,128,128);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">/**<br> * Read the session<br>
* @param int session id<br> * @return string string of the sessoin<br> */<br> </span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">public function </span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">read</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">(</span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">$id</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">) {<br>
<br> </span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">$id </span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">= </span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">mysql_real_escape_string</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">(</span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">$id</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">);<br>
</span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">$sql </span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">= </span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">sprintf</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">(</span><span class="" style="color:rgb(204,51,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">"SELECT `data` FROM `sessions` " </span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">.<br>
</span><span class="" style="color:rgb(204,51,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">"WHERE id = '%s'"</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">, </span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">$id</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">);<br>
if (</span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">$result </span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">= </span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">mysql_query</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">(</span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">$sql</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">, </span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">$this</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">-></span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">_sess_db</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">)) {<br>
if (</span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">mysql_num_rows</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">(</span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">$result</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">)) {<br>
</span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">$record </span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">= </span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">mysql_fetch_assoc</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">(</span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">$result</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">);<br>
return </span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">$record</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">[</span><span class="" style="color:rgb(204,51,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">'data'</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">];<br>
}<br> }<br> return </span><span class="" style="color:rgb(204,51,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">''</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">;<br>
<br> }<br><br> </span><span class="" style="color:rgb(128,128,128);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">/**<br> * Write the session<br>
* @param int session id<br> * @param string data of the session<br> */<br> </span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">public function </span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">write</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">(</span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">$id</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">, </span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">$data</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">) {<br>
<br> </span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">$sql </span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">= </span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">sprintf</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">(</span><span class="" style="color:rgb(204,51,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">"REPLACE INTO `sessions` VALUES('%s', '%s', '%s')"</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">,<br>
</span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">mysql_real_escape_string</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">(</span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">$id</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">),<br>
</span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">mysql_real_escape_string</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">(</span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">$data</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">),<br>
</span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">mysql_real_escape_string</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">(</span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">time</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">()));<br>
return </span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">mysql_query</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">(</span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">$sql</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">, </span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">$this</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">-></span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">_sess_db</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">);<br>
<br> }<br><br> </span><span class="" style="color:rgb(128,128,128);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">/**<br> * Destoroy the session<br>
* @param int session id<br> * @return bool<br> */<br> </span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">public function </span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">destroy</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">(</span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">$id</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">) {<br>
<br> </span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">$sql </span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">= </span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">sprintf</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">(</span><span class="" style="color:rgb(204,51,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">"DELETE FROM `sessions` WHERE `id` = '%s'"</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">, </span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">$id</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">);<br>
return </span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">mysql_query</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">(</span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">$sql</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">, </span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">$this</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">-></span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">_sess_db</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">);<br>
<br>}<br><br> </span><span class="" style="color:rgb(128,128,128);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">/**<br> * Garbage Collector<br>
* @param int life time (sec.)<br> * @return bool<br> * @see session.gc_divisor 100<br> * @see session.gc_maxlifetime 1440<br> * @see session.gc_probability 1<br> * @usage execution rate 1/100<br>
* (session.gc_probability/session.gc_divisor)<br> */<br> </span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">public function </span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">gc</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">(</span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">$max</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">) {<br>
<br> </span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">$sql </span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">= </span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">sprintf</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">(</span><span class="" style="color:rgb(204,51,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">"DELETE FROM `sessions` WHERE `timestamp` < '%s'"</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">,<br>
</span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">mysql_real_escape_string</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">(</span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">time</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">() - </span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">$max</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">));<br>
return </span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">mysql_query</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">(</span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">$sql</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">, </span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">$this</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">-></span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">_sess_db</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">);<br>
<br> }<br><br>}<br><br></span><span class="" style="color:rgb(128,128,128);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">//ini_set('session.gc_probability', 50);<br>
</span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">ini_set</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">(</span><span class="" style="color:rgb(204,51,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">'session.save_handler'</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">, </span><span class="" style="color:rgb(204,51,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">'user'</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">);<br>
<br></span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">$session </span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">= new </span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">Session</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">();<br>
</span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">session_set_save_handler</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">(array(</span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">$session</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">, </span><span class="" style="color:rgb(204,51,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">'open'</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">),<br>
array(</span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">$session</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">, </span><span class="" style="color:rgb(204,51,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">'close'</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">),<br>
array(</span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">$session</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">, </span><span class="" style="color:rgb(204,51,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">'read'</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">),<br>
array(</span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">$session</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">, </span><span class="" style="color:rgb(204,51,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">'write'</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">),<br>
array(</span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">$session</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">, </span><span class="" style="color:rgb(204,51,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">'destroy'</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">),<br>
array(</span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">$session</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">, </span><span class="" style="color:rgb(204,51,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">'gc'</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">));<br>
<br></span><span class="" style="color:rgb(128,128,128);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">// below sample main<br><br></span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">session_start</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">();<br>
</span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">session_regenerate_id</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">(</span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">true</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">);<br>
<br>if (isset(</span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">$_SESSION</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">[</span><span class="" style="color:rgb(204,51,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">'counter'</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">])) {<br>
</span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">$_SESSION</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">[</span><span class="" style="color:rgb(204,51,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">'counter'</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">]++;<br>
} else {<br> </span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">$_SESSION</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">[</span><span class="" style="color:rgb(204,51,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">'counter'</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">] = </span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">1</span><span class="" style="color:rgb(102,153,51);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">;<br>
}<br><br></span><span class="" style="color:rgb(51,102,153);background-color:rgb(242,242,242);font-family:'Source Code Pro',monospace;font-size:14px;line-height:20.440000534057617px">?></span></div><div><font color="#336699" face="Source Code Pro, monospace"><span style="font-size:14px;line-height:20.440000534057617px"><br>
</span></font></div><div><div><b><font color="#ff0000">Dudas:</font></b></div><div><b><font color="#ff0000"><br></font></b></div><div><b><font color="#ff0000">1- Suponiendo que yo tengo una base de datos creada, con una tabla de usuarios con nombres de usuarios y passwords, ¿debo armar otra tabla para almacenar los datos de las sesiones, cierto? o debo armar otra base de datos distinta para las sesiones?<br>
</font></b></div><div><b><font color="#ff0000"><br></font></b></div><div><b><font color="#ff0000">2- Solo con incluir el script con el manejador de sesiones y escribir "session_start();" en mi script php alcanza para que php se encargue de las sesiones de manera transparente al usuario?</font></b></div>
<div><b><font color="#ff0000"><br></font></b></div><div><b><font color="#ff0000">2- No entiendo cómo puedo aplicar este ejemplo a mi trabajo final, en el cual ya tengo la base de datos y la tabla de usuarios autorizados para ingresar al sistema. Me podrías encaminar un poco con eso?</font></b></div>
<div><br></div>-- <br><div dir="ltr"><div><b><font face="trebuchet ms, sans-serif">Ing. Maximiliano Andrés Lizondo</font></b></div><ul><li style="text-align:left"><font><i>Teléfonos: </i><font face="tahoma, sans-serif"><b>0223-493-5488</b> (particular) - <b>2236-321708</b> (móvil)</font><br>
</font></li><li style="font-style:italic;text-align:left"><font><i>Perfil profesional en <b>LinkedIn</b>: </i><a href="http://ar.linkedin.com/pub/maximiliano-andr%C3%A9s-lizondo/61/906/344" style="font-style:normal;color:rgb(17,85,204)" target="_blank">http://ar.linkedin.com/pub/maximiliano-andr%C3%A9s-lizondo/61/906/344</a></font><br>
</li></ul></div>
</div></div>