ElaKiri Community
Downloads
Go Back   ElaKiri Community > Computers & Internet > Web Development
Reload this Page PHP Lesson 08 - Sessions
Reply
 
Thread Tools
(#1)
Old
P_Namal's Avatar
P_Namal P_Namal is offline
Senior Member
P_Namal is just really niceP_Namal is just really niceP_Namal is just really niceP_Namal is just really niceP_Namal is just really niceP_Namal is just really niceP_Namal is just really niceP_Namal is just really nice
 
Posts: 873
Join Date: Oct 2007
Location: https://storemate.lk
smile PHP Lesson 08 - Sessions - 05-22-2014, 11:21 AM

Previous Posts ....

Lesson 01 - PHP අට්ටාලය ගහගමු

Lesson 02 - Form එකක තියෙන data, Database එකකට දාමු

Lesson 03 - Database එකේ තියන data view කරගමු

Lesson 04 - මෙන්න update delete

Lesson 05 - Arrays

Lesson 06 - empty(), isset()

Lesson 07 - php with linux


sessions කියන්නේ site එකකට log වෙන තනි user කෙනෙක්ගේ Data තියාගන්න පුලුවන් සහ site එකේ ඕනම තැනකදි ඒ data Access කරන්න පුලුවන් PHP වල තියෙන සරල විදියක්. මේකේදි log වෙන userටම සුවිශේෂ වූ (Unique) session ID එකක් generate කරලා ඒ ID එකෙන් අදාල user ව හදුනාගනු ලබනවා. Site එකේ කොතනකදි හරි session එකක් start කරන කොට දැනට generate කරපු ID එකක් නැත්තම් අලුතෙන් ID එකක් හදාගන්නවා. තියෙනවා නම ඒ ID එකම පාවිච්චි කරනවා.

සාමාන්‍යයෙන් PHP variable store වෙන්නේ RAM එකේ නිසා ඒවායේ ආයු කාලය එ් ඒ variable type එක අනුව පොඩි කාලයක්. නමුත් session variable වල වෙනස, එම data වෙනම temporary file එකක save කිරිමයි. ඒ නිසා ඒ Data access කරන්න පුලුවන් පරාසය වැඩියි. ඒකයි $_SESSION variable එක ‘super global variable’ එකක් කියන්නේ. $_COOKIE කියන්නෙත් ඒ වගේ එකක්. (ඒ data save වෙන්නේ userගේ browser එකේ.)

සාමාන්‍යයෙන් generate කරපු session ID එක store වෙලා තියෙන්නේ user browser එකේ cookies වල. නමුත් session data store වෙන්නේ server එකේ temporary file එකක encrypt වෙලා. ඒ data, $_SESSION කියන super global variable (Array එකක්) එකෙන් access කරන්න පුලුවන්.

PHP Code:
<?php session_start(); ?>
මේ function එකෙන් තමයි unique session ID එකක් generate වෙලා ඒක user browser එකේ save වෙන්නේ.

අපි දැන් $_COOKIE variable එකේ මොනාද තියෙන්නේ කියලා බැලුවොත්,



PHP Code:
<?php
session_start
();

var_dump($_COOKIE);
 
?>
PHP Code:
OUTPUT :
array(
3) { ["background_style"]=> string(15"boxed pattern-1" ["__atuvc"]=> string(26"33|13,0|14,0|15,0|16,20|17" ["PHPSESSID"]=> string(26"j50s67099impujpsqlgmv3bvp3" 

මේ array එකේ තියෙන values ඔයාලගේ වෙනස් වෙන්න පුලුවන්. නමුත් PHPSESSID කියලා array key එකක් අනිවා තියෙන්න ඕනි. ඒ key එකට අදාල value එකේ generate වෙච්ච session ID එක save වෙලා තියෙනවා.

PHP Code:
["PHPSESSID"]=> string(26"j50s67099impujpsqlgmv3bvp3" 
$_SESSION varible එකේ මොනාද තියෙන්නේ කියලා බලමු.

PHP Code:
<?php
session_start
();

var_dump($_SESSION);
 
?>
PHP Code:
OUTPUT:
array(
0) { } 
මේ array එක හිස් එකක්. මේකට හේතුව අපි තාම session variable එකට data දාපු නැති නිසා. session variable එකට data දැමීම normal array එකකට data assign කරනවා වගේ කරන්න පුලුවන්.

PHP Code:
Ex:
$_SESSION[‘user_name’] = ‘Gama Raala’;
$_SESSION[‘user_id’] = ‘1823’
දැන් මේ variable අපේ domain එකේ ඕනම page එකකදී access කරන්න පුලුවන්.

PHP Code:
echo $_SESSION[‘user_name’];

OUTPUT:
Gama Raala
user කෙනෙක් site එකකට log වුනාම මූලිකවම session array එක userගේ registered data වලින් පුරවනවා. site එකේ functions run වෙන්න ඒ data යොදාගෙන user logout වුනාම ඒ data remove කරනවා. Browser එක ‘close කරොත් ඉබේ ඒ data අයින් වෙලා යනවා.

session එකක් manually remove කරන්න නම් session_destroy() හෝ session_unset() use කරලා මුලු session data ටිකම remove කරන්න පුලුවන්.

session data save වෙන path එක linux OS වල නම් normally /tmp folder එකේ. අපේ OS එකේ කොහෙද save වෙන්නේ කියලා බලාගන්න php.ini file එකේ session.save_path parameter එක බලන්න.

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /customers/b/2/5/edited.com/httpd.www/beta/login.php:1) in /customers/b/2/5/edited.com/httpd.www/beta/inc/sessions.inc.php on line 11

sessions වලදි එන පොදු error එකක් තමයි මේ. මේකට හේතුව session_start එකට කලින් මොනා හරි content එකක් තිබීම. ඒක space එකක් විතරක් වෙන්නත් පුලුවන්. <?php tag එකට පස්සේ මුලින්ම තියෙන code එක session_start වෙන්න ඕනිි.

PHP Code:
<?php
session_start
();
?>
Reply With Quote
(#2)
Old
Sandaru Kalhara Sandaru Kalhara is offline
Senior Member
Sandaru Kalhara has a spectacular aura aboutSandaru Kalhara has a spectacular aura aboutSandaru Kalhara has a spectacular aura about
 
Posts: 951
Join Date: Apr 2014
05-22-2014, 11:22 AM

valuable post
Reply With Quote
(#3)
Old
sujeewahms's Avatar
sujeewahms sujeewahms is offline
Senior Member
sujeewahms is a glorious beacon of lightsujeewahms is a glorious beacon of lightsujeewahms is a glorious beacon of lightsujeewahms is a glorious beacon of lightsujeewahms is a glorious beacon of lightsujeewahms is a glorious beacon of lightsujeewahms is a glorious beacon of lightsujeewahms is a glorious beacon of lightsujeewahms is a glorious beacon of lightsujeewahms is a glorious beacon of lightsujeewahms is a glorious beacon of light
 
Posts: 1,814
Join Date: Nov 2008
Location: Narammala
Send a message via Skype™ to sujeewahms
05-22-2014, 11:27 AM

ela machan
Reply With Quote
(#4)
Old
Fox Mulder89's Avatar
Fox Mulder89 Fox Mulder89 is offline
Senior Member
Fox Mulder89 is a glorious beacon of lightFox Mulder89 is a glorious beacon of lightFox Mulder89 is a glorious beacon of lightFox Mulder89 is a glorious beacon of lightFox Mulder89 is a glorious beacon of lightFox Mulder89 is a glorious beacon of lightFox Mulder89 is a glorious beacon of lightFox Mulder89 is a glorious beacon of lightFox Mulder89 is a glorious beacon of lightFox Mulder89 is a glorious beacon of lightFox Mulder89 is a glorious beacon of light
 
Posts: 2,818
Join Date: Dec 2012
Location: gampaha
05-22-2014, 11:59 AM

bump
Reply With Quote
(#5)
Old
Vladimir Putin's Avatar
Vladimir Putin Vladimir Putin is offline
Senior Member
Vladimir Putin has a spectacular aura aboutVladimir Putin has a spectacular aura about
 
Posts: 1,411
Join Date: Apr 2014
05-22-2014, 12:11 PM

very very good post. machan Lynda wala wage elakiri eka wenuwen loweth nethi wenna video tuts tikak karamuda ?
Reply With Quote
(#6)
Old
P_Namal's Avatar
P_Namal P_Namal is offline
Senior Member
P_Namal is just really niceP_Namal is just really niceP_Namal is just really niceP_Namal is just really niceP_Namal is just really niceP_Namal is just really niceP_Namal is just really niceP_Namal is just really nice
 
Posts: 873
Join Date: Oct 2007
Location: https://storemate.lk
05-22-2014, 12:12 PM

Quote:
Originally Posted by Vladimir Putin View Post
very very good post. machan Lynda wala wage elakiri eka wenuwen loweth nethi wenna video tuts tikak karamuda ?
Karanna nam puluwan mcn. eth welawa thamai aula.
Reply With Quote
(#7)
Old
arrow__'s Avatar
arrow__ arrow__ is offline
Senior Member
arrow__ is just really nicearrow__ is just really nicearrow__ is just really nicearrow__ is just really nicearrow__ is just really nicearrow__ is just really nicearrow__ is just really nicearrow__ is just really nicearrow__ is just really nicearrow__ is just really nice
 
Posts: 5,187
Join Date: Jul 2013
05-22-2014, 12:12 PM

patta macho
Reply With Quote
(#8)
Old
olu bakka's Avatar
olu bakka olu bakka is offline
Senior Member
olu bakka is a glorious beacon of lightolu bakka is a glorious beacon of lightolu bakka is a glorious beacon of lightolu bakka is a glorious beacon of lightolu bakka is a glorious beacon of lightolu bakka is a glorious beacon of lightolu bakka is a glorious beacon of lightolu bakka is a glorious beacon of lightolu bakka is a glorious beacon of lightolu bakka is a glorious beacon of lightolu bakka is a glorious beacon of light
 
Posts: 6,762
Join Date: Aug 2011
05-22-2014, 12:15 PM

pattayi digatama karagena yanna
Reply With Quote
(#9)
Old
Vladimir Putin's Avatar
Vladimir Putin Vladimir Putin is offline
Senior Member
Vladimir Putin has a spectacular aura aboutVladimir Putin has a spectacular aura about
 
Posts: 1,411
Join Date: Apr 2014
05-22-2014, 12:16 PM

Quote:
Originally Posted by P_Namal View Post
Karanna nam puluwan mcn. eth welawa thamai aula.
loweth nethi wenna script eka liyala kara nam maru. Aluth cam ekak next two weeks athule ganna hithan inne. will see.
Reply With Quote
(#10)
Old
ilanganthilaka's Avatar
ilanganthilaka ilanganthilaka is offline
Senior Member
ilanganthilaka is a name known to allilanganthilaka is a name known to allilanganthilaka is a name known to allilanganthilaka is a name known to allilanganthilaka is a name known to allilanganthilaka is a name known to allilanganthilaka is a name known to allilanganthilaka is a name known to allilanganthilaka is a name known to allilanganthilaka is a name known to allilanganthilaka is a name known to all
 
Posts: 13,978
Join Date: Jun 2008
05-22-2014, 12:22 PM

ELA WADAK
Reply With Quote
Reply

Bookmarks

Tags
php, sessions, webdevelopment

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



Copyright © 2006 - 2011 ElaKiri™ Beta2.Evo vBulletin, vBa iBproArcade Subdreamer I-Magic MKv

Page generated in 0.02725 seconds with 9 queries