© Khmer Angkor Academy - sophearithput168

Session

អំពី Session

Session គឺ​ជា​វិធី​រក្សាទុក​ព័ត៌មាន​របស់​អ្នក​ប្រើប្រាស់​នៅ​លើ Server (មិនមែន​នៅ Browser)។ Session សុវត្ថិភាព​ជាង Cookie ព្រោះ​ទិន្នន័យ​ត្រូវ​បាន​រក្សាទុក​នៅ Server ហើយ​អ្នក​ប្រើប្រាស់​មិន​អាច​កែ​បាន។

Session vs Cookie:

  • Session: ទិន្នន័យ​នៅ Server, សុវត្ថិភាព​ខ្ពស់, ផុតកំណត់​ពេល​បិទ Browser
  • Cookie: ទិន្នន័យ​នៅ Browser, សុវត្ថិភាព​ទាប, អាច​កំណត់​ពេល​ផុតកំណត់
PHP Code
Click "Run" to execute the PHP code

ចាប់​ផ្ដើម Session

មុន​ពេល​ប្រើ Session ត្រូវ​ហៅ session_start() នៅ​ដើម​ឯកសារ

PHP Code
Click "Run" to execute the PHP code

រក្សាទុក និង​អាន​ទិន្នន័យ

ប្រើ $_SESSION superglobal array ដើម្បី​រក្សាទុក និង​អាន​ទិន្នន័យ

PHP Code
Click "Run" to execute the PHP code

លុប​ទិន្នន័យ Session

វិធី​ផ្សេងៗ​ក្នុង​ការ​លុប​ទិន្នន័យ Session

PHP Code
Click "Run" to execute the PHP code

ឧទាហរណ៍​ជាក់ស្តែង

1. Login System (ប្រព័ន្ធ​ចូល​គណនី)

PHP Code
Click "Run" to execute the PHP code

2. Multi-Step Form (ទម្រង់​ច្រើន​ជំហាន)

PHP Code
Click "Run" to execute the PHP code

3. Flash Messages (សារ​បណ្តោះអាសន្ន)

PHP Code
Click "Run" to execute the PHP code

4. Page View Counter (ការ​រាប់​ទំព័រ)

PHP Code
Click "Run" to execute the PHP code