ยินดีต้อนรับคุณ, บุคคลทั่วไป กรุณา เข้าสู่ระบบ หรือ ลงทะเบียน

เข้าสู่ระบบด้วยชื่อผู้ใช้ รหัสผ่าน และระยะเวลาในเซสชั่น

ThaiSEOBoard.comพัฒนาเว็บไซต์ProgrammingMake Your Sessions More Security by storing session data in a MySQL
หน้า: [1]   ลงล่าง
พิมพ์
ผู้เขียน หัวข้อ: Make Your Sessions More Security by storing session data in a MySQL  (อ่าน 616 ครั้ง)
0 สมาชิก และ 1 บุคคลทั่วไป กำลังดูหัวข้อนี้
astkboy2008
Newbie
*

พลังน้ำใจ: 6
ออฟไลน์ ออฟไลน์

กระทู้: 33



ดูรายละเอียด
« เมื่อ: 06 มกราคม 2010, 19:53:35 »

storing session data in a MySQL required a php class
this class is PHP Sessions Management 1.0.1
This class implements a new PHP session handler that can replace the default PHP session handler by storing session data in a MySQL database table.

 The session handler works just by creating an object of this class. After that, applications just need to use the same code to store and retrieve session variables.
How Ican Use it?
its very easy just see this example
examples/example.php
<?php

    
// first create the required mySQL table that is used by this class
    // you can do that by running in mySQL the "session_data.sql" file
    // from the "install" folder!
    
    // change the next values to match the setting of your mySQL database
    
$mySQLHost "localhost";
    
$mySQLUsername "username";
    
$mySQLPassword "password";
    
    
// this is the name of the database where you created the table
    // used by this class
    
$mySQLDatabase "database";
    
    
$link mysql_connect($mySQLHost$mySQLUsername$mySQLPassword);

    if (!
$link) {

        die (
"Could not connect to database!");

    }

    
$db mysql_select_db($mySQLDatabase$link);

    if (!
$db) {

        die (
"Could not select database!");

    }

    
// include the session manager class
    
require "../class.dbsession.php";
    
    
// instantiate a new session object
    // note that you don&#39;t need to call the session_start() function
    // as it is called automatically when the object is instantiated
    
$session = new dbsession();

    
// from now on, use sessions as you would normally
    // the only difference is that session data is no longer saved on the server
    // but in your database, making the data in it more secure
    
    
print_r("
        The first time you run the script there should be an empty array (as there&#39;s nothing in the
\$_SESSION array)<br />
        After you press \"refresh\" on your browser you will se the values that were
written in the \$_SESSION array<br>
    "
);
    
print_r("<pre>");
    
print_r($_SESSION);
    
print_r("</pre>");

    
// add some values to the session
    
$_SESSION["value1"] = "hello";
    
$_SESSION["value2"] = "world";
    
    
// now check the table and see that there is data in it!
    
    // to completely delete a session uncomment the following line
    
    //$session->stop();
?>


and the session will store in the mysql after that

บันทึกการเข้า
หน้า: [1]   ขึ้นบน
พิมพ์