Search
Search titles only
By:
Search titles only
By:
Log in
Register
Search
Search titles only
By:
Search titles only
By:
Menu
Install the app
Install
Forums
New posts
All threads
Latest threads
New posts
Trending threads
Trending
Search forums
What's new
New posts
New ads
New profile posts
Latest activity
Free Ads
Latest reviews
Search ads
Members
Current visitors
New profile posts
Search profile posts
Contact us
Latest ads
Pure VPN - Up to 27 Months
vgp
Updated:
Friday at 8:10 AM
එක පැකේජ් එකයි මාසෙටම Unlimited Internet. තාමත් DATA CARD දාන්න සල්ලි වියදම් කරනවද? අඩුම මිලට අපෙන්.
sayuru bandara
Updated:
Jun 2, 2026
Ad icon
ඉන්ටර්නෙට් එකෙන් හරියටම සල්ලි හොයන්න සහ Success වෙන්න කැමතිද? 🚀 (E-Money & Success Stories)
siri sumana
Updated:
May 30, 2026
Gemini AI PRO 18 months Offer
Hawaka
Updated:
May 27, 2026
Ad icon
koko account
DasunEranga
Updated:
May 27, 2026
Electronics
Vehicles
Property
Search
Reply to thread
Forums
Computers & Internet
Software Development
PHP Lesson 08 - Sessions
Get the App
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Message
<blockquote data-quote="P_Namal" data-source="post: 16689011" data-attributes="member: 54700"><p><span style="color: Black"><span style="font-size: 18px">Previous Posts ....</span></span></p><p></p><p><span style="font-size: 15px"><a href="http://www.elakiri.com/forum/showpost.php?p=12780302&postcount=3" target="_blank"><span style="color: Blue">Lesson 01 - PHP අට්ටාලය ගහගමු</span> </a></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"><a href="http://www.elakiri.com/forum/showpost.php?p=12780366&postcount=4" target="_blank"><span style="color: Blue">Lesson 02 - Form එකක තියෙන data, Database එකකට දාමු</span> </a></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"><a href="http://www.elakiri.com/forum/showpost.php?p=12782274&postcount=29" target="_blank"><span style="color: Blue">Lesson 03 - Database එකේ තියන data view කරගමු</span> </a></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"><a href="http://www.elakiri.com/forum/showpost.php?p=13005426&postcount=47" target="_blank"><span style="color: Blue">Lesson 04 - මෙන්න update delete</span> </a></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"><a href="http://www.elakiri.com/forum/showpost.php?p=16106832&postcount=117" target="_blank"><span style="color: Blue">Lesson 05 - Arrays </span> </a></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"><a href="http://www.elakiri.com/forum/showpost.php?p=16132019&postcount=154" target="_blank"><span style="color: Blue">Lesson 06 - empty(), isset() </span> </a></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"><a href="http://www.elakiri.com/forum/showpost.php?p=16144269&postcount=162" target="_blank"><span style="color: Blue">Lesson 07 - php with linux</span></a> </span></p><p></p><p><span style="color: DarkRed"><span style="font-size: 15px">sessions කියන්නේ site එකකට log වෙන තනි user කෙනෙක්ගේ Data තියාගන්න පුලුවන් සහ site එකේ ඕනම තැනකදි ඒ data Access කරන්න පුලුවන් PHP වල තියෙන සරල විදියක්. මේකේදි log වෙන userටම සුවිශේෂ වූ (Unique) session ID එකක් generate කරලා ඒ ID එකෙන් අදාල user ව හදුනාගනු ලබනවා. Site එකේ කොතනකදි හරි session එකක් start කරන කොට දැනට generate කරපු ID එකක් නැත්තම් අලුතෙන් ID එකක් හදාගන්නවා. තියෙනවා නම ඒ ID එකම පාවිච්චි කරනවා. </span></span></p><p><span style="color: DarkRed"><span style="font-size: 15px"></span></span></p><p><span style="color: DarkRed"><span style="font-size: 15px">සාමාන්යයෙන් PHP variable store වෙන්නේ RAM එකේ නිසා ඒවායේ ආයු කාලය එ් ඒ variable type එක අනුව පොඩි කාලයක්. නමුත් session variable වල වෙනස, එම data වෙනම temporary file එකක save කිරිමයි. ඒ නිසා ඒ Data access කරන්න පුලුවන් පරාසය වැඩියි. ඒකයි $_SESSION variable එක ‘super global variable’ එකක් කියන්නේ. $_COOKIE කියන්නෙත් ඒ වගේ එකක්. (ඒ data save වෙන්නේ userගේ browser එකේ.)</span></span></p><p><span style="color: DarkRed"><span style="font-size: 15px"></span></span></p><p><span style="color: DarkRed"><span style="font-size: 15px">සාමාන්යයෙන් generate කරපු session ID එක store වෙලා තියෙන්නේ user browser එකේ cookies වල. නමුත් session data store වෙන්නේ server එකේ temporary file එකක encrypt වෙලා. ඒ data, $_SESSION කියන super global variable (Array එකක්) එකෙන් access කරන්න පුලුවන්. </span></span></p><p><span style="color: DarkRed"><span style="font-size: 15px"></span></span></p><p><span style="color: DarkRed"><span style="font-size: 15px">[PHP]<?php session_start(); ?>[/PHP]</span></span></p><p><span style="color: DarkRed"><span style="font-size: 15px"></span></span></p><p><span style="color: DarkRed"><span style="font-size: 15px">මේ function එකෙන් තමයි unique session ID එකක් generate වෙලා ඒක user browser එකේ save වෙන්නේ.</span></span></p><p><span style="color: DarkRed"><span style="font-size: 15px"></span></span></p><p><span style="color: DarkRed"><span style="font-size: 15px">අපි දැන් $_COOKIE variable එකේ මොනාද තියෙන්නේ කියලා බැලුවොත්,</span></span></p><p><span style="color: DarkRed"><span style="font-size: 15px"></span></span></p><p><span style="color: DarkRed"><span style="font-size: 15px"><img src="http://parallax.lk/images/blog/cookies.jpg" alt="" class="fr-fic fr-dii fr-draggable " style="" /></span></span></p><p><span style="color: DarkRed"><span style="font-size: 15px"></span></span></p><p><span style="color: DarkRed"><span style="font-size: 15px">[PHP]<?php</span></span></p><p><span style="color: DarkRed"><span style="font-size: 15px">session_start();</span></span></p><p><span style="color: DarkRed"><span style="font-size: 15px"></span></span></p><p><span style="color: DarkRed"><span style="font-size: 15px">var_dump($_COOKIE);</span></span></p><p> <span style="color: DarkRed"><span style="font-size: 15px">?>[/PHP]</span></span></p><p><span style="color: DarkRed"><span style="font-size: 15px"></span></span></p><p><span style="color: DarkRed"><span style="font-size: 15px">[PHP]OUTPUT :</span></span></p><p><span style="color: DarkRed"><span style="font-size: 15px">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" }</span></span></p><p><span style="color: DarkRed"><span style="font-size: 15px">[/PHP]</span></span></p><p><span style="color: DarkRed"><span style="font-size: 15px"></span></span></p><p><span style="color: DarkRed"><span style="font-size: 15px"></span></span></p><p><span style="color: DarkRed"><span style="font-size: 15px">මේ array එකේ තියෙන values ඔයාලගේ වෙනස් වෙන්න පුලුවන්. නමුත් PHPSESSID කියලා array key එකක් අනිවා තියෙන්න ඕනි. ඒ key එකට අදාල value එකේ generate වෙච්ච session ID එක save වෙලා තියෙනවා. </span></span></p><p><span style="color: DarkRed"><span style="font-size: 15px"></span></span></p><p><span style="color: DarkRed"><span style="font-size: 15px">[PHP]["PHPSESSID"]=> string(26) "j50s67099impujpsqlgmv3bvp3" }[/PHP]</span></span></p><p><span style="color: DarkRed"><span style="font-size: 15px"></span></span></p><p><span style="color: DarkRed"><span style="font-size: 15px">$_SESSION varible එකේ මොනාද තියෙන්නේ කියලා බලමු. </span></span></p><p><span style="color: DarkRed"><span style="font-size: 15px"></span></span></p><p><span style="color: DarkRed"><span style="font-size: 15px">[PHP]<?php</span></span></p><p><span style="color: DarkRed"><span style="font-size: 15px">session_start();</span></span></p><p><span style="color: DarkRed"><span style="font-size: 15px"></span></span></p><p><span style="color: DarkRed"><span style="font-size: 15px">var_dump($_SESSION);</span></span></p><p> <span style="color: DarkRed"><span style="font-size: 15px">?>[/PHP]</span></span></p><p> <span style="color: DarkRed"><span style="font-size: 15px"></span></span></p><p><span style="color: DarkRed"><span style="font-size: 15px">[PHP]OUTPUT:</span></span></p><p><span style="color: DarkRed"><span style="font-size: 15px">array(0) { }[/PHP]</span></span></p><p><span style="color: DarkRed"><span style="font-size: 15px"></span></span></p><p><span style="color: DarkRed"><span style="font-size: 15px">මේ array එක හිස් එකක්. මේකට හේතුව අපි තාම session variable එකට data දාපු නැති නිසා. session variable එකට data දැමීම normal array එකකට data assign කරනවා වගේ කරන්න පුලුවන්.</span></span></p><p><span style="color: DarkRed"><span style="font-size: 15px"></span></span></p><p><span style="color: DarkRed"><span style="font-size: 15px">[PHP]Ex:</span></span></p><p><span style="color: DarkRed"><span style="font-size: 15px">$_SESSION[‘user_name’] = ‘Gama Raala’;</span></span></p><p><span style="color: DarkRed"><span style="font-size: 15px">$_SESSION[‘user_id’] = ‘1823’;[/PHP]</span></span></p><p><span style="color: DarkRed"><span style="font-size: 15px"></span></span></p><p><span style="color: DarkRed"><span style="font-size: 15px">දැන් මේ variable අපේ domain එකේ ඕනම page එකකදී access කරන්න පුලුවන්.</span></span></p><p><span style="color: DarkRed"><span style="font-size: 15px"></span></span></p><p><span style="color: DarkRed"><span style="font-size: 15px">[PHP]echo $_SESSION[‘user_name’];</span></span></p><p><span style="color: DarkRed"><span style="font-size: 15px"></span></span></p><p><span style="color: DarkRed"><span style="font-size: 15px">OUTPUT:</span></span></p><p><span style="color: DarkRed"><span style="font-size: 15px">Gama Raala;[/PHP]</span></span></p><p><span style="color: DarkRed"><span style="font-size: 15px"></span></span></p><p><span style="color: DarkRed"><span style="font-size: 15px">user කෙනෙක් site එකකට log වුනාම මූලිකවම session array එක userගේ registered data වලින් පුරවනවා. site එකේ functions run වෙන්න ඒ data යොදාගෙන user logout වුනාම ඒ data remove කරනවා. Browser එක ‘close කරොත් ඉබේ ඒ data අයින් වෙලා යනවා.</span></span></p><p><span style="color: DarkRed"><span style="font-size: 15px"></span></span></p><p><span style="color: DarkRed"><span style="font-size: 15px">session එකක් manually remove කරන්න නම් session_destroy() හෝ session_unset() use කරලා මුලු session data ටිකම remove කරන්න පුලුවන්. </span></span></p><p><span style="color: DarkRed"><span style="font-size: 15px"></span></span></p><p><span style="color: DarkRed"><span style="font-size: 15px">session data save වෙන path එක linux OS වල නම් normally /tmp folder එකේ. අපේ OS එකේ කොහෙද save වෙන්නේ කියලා බලාගන්න php.ini file එකේ session.save_path parameter එක බලන්න.</span></span></p><p><span style="color: DarkRed"><span style="font-size: 15px"></span></span></p><p><span style="color: DarkRed"><span style="font-size: 15px"><span style="color: Blue">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</span></span></span></p><p><span style="color: DarkRed"><span style="font-size: 15px"></span></span></p><p><span style="color: DarkRed"><span style="font-size: 15px">sessions වලදි එන පොදු error එකක් තමයි මේ. මේකට හේතුව session_start එකට කලින් මොනා හරි content එකක් තිබීම. ඒක space එකක් විතරක් වෙන්නත් පුලුවන්. <?php tag එකට පස්සේ මුලින්ම තියෙන code එක session_start වෙන්න ඕනිි.</span></span></p><p><span style="color: DarkRed"><span style="font-size: 15px"></span></span></p><p><span style="color: DarkRed"><span style="font-size: 15px">[PHP]<?php</span></span></p><p><span style="color: DarkRed"><span style="font-size: 15px">session_start();</span></span></p><p><span style="color: DarkRed"><span style="font-size: 15px">?>[/PHP]</span></span></p><p><span style="color: DarkRed"><span style="font-size: 15px"></span></span></p></blockquote><p></p>
[QUOTE="P_Namal, post: 16689011, member: 54700"] [COLOR="Black"][SIZE="5"]Previous Posts ....[/SIZE][/COLOR] [SIZE="4"][URL="http://www.elakiri.com/forum/showpost.php?p=12780302&postcount=3"][COLOR="Blue"]Lesson 01 - PHP අට්ටාලය ගහගමු[/COLOR] [/URL] [URL="http://www.elakiri.com/forum/showpost.php?p=12780366&postcount=4"][COLOR="Blue"]Lesson 02 - Form එකක තියෙන data, Database එකකට දාමු[/COLOR] [/URL] [URL="http://www.elakiri.com/forum/showpost.php?p=12782274&postcount=29"][COLOR="Blue"]Lesson 03 - Database එකේ තියන data view කරගමු[/COLOR] [/URL] [URL="http://www.elakiri.com/forum/showpost.php?p=13005426&postcount=47"][COLOR="Blue"]Lesson 04 - මෙන්න update delete[/COLOR] [/URL] [URL="http://www.elakiri.com/forum/showpost.php?p=16106832&postcount=117"][COLOR="Blue"]Lesson 05 - Arrays [/COLOR] [/URL] [URL="http://www.elakiri.com/forum/showpost.php?p=16132019&postcount=154"][COLOR="Blue"]Lesson 06 - empty(), isset() [/COLOR] [/URL] [URL="http://www.elakiri.com/forum/showpost.php?p=16144269&postcount=162"][COLOR="Blue"]Lesson 07 - php with linux[/COLOR][/URL][COLOR="Blue"] [/COLOR] [/SIZE] [COLOR="DarkRed"][SIZE="4"]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]<?php session_start(); ?>[/PHP] මේ function එකෙන් තමයි unique session ID එකක් generate වෙලා ඒක user browser එකේ save වෙන්නේ. අපි දැන් $_COOKIE variable එකේ මොනාද තියෙන්නේ කියලා බැලුවොත්, [IMG]http://parallax.lk/images/blog/cookies.jpg[/IMG] [PHP]<?php session_start(); var_dump($_COOKIE); ?>[/PHP] [PHP]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" } [/PHP] මේ array එකේ තියෙන values ඔයාලගේ වෙනස් වෙන්න පුලුවන්. නමුත් PHPSESSID කියලා array key එකක් අනිවා තියෙන්න ඕනි. ඒ key එකට අදාල value එකේ generate වෙච්ච session ID එක save වෙලා තියෙනවා. [PHP]["PHPSESSID"]=> string(26) "j50s67099impujpsqlgmv3bvp3" }[/PHP] $_SESSION varible එකේ මොනාද තියෙන්නේ කියලා බලමු. [PHP]<?php session_start(); var_dump($_SESSION); ?>[/PHP] [PHP]OUTPUT: array(0) { }[/PHP] මේ array එක හිස් එකක්. මේකට හේතුව අපි තාම session variable එකට data දාපු නැති නිසා. session variable එකට data දැමීම normal array එකකට data assign කරනවා වගේ කරන්න පුලුවන්. [PHP]Ex: $_SESSION[‘user_name’] = ‘Gama Raala’; $_SESSION[‘user_id’] = ‘1823’;[/PHP] දැන් මේ variable අපේ domain එකේ ඕනම page එකකදී access කරන්න පුලුවන්. [PHP]echo $_SESSION[‘user_name’]; OUTPUT: Gama Raala;[/PHP] 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 එක බලන්න. [COLOR="Blue"]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[/COLOR] sessions වලදි එන පොදු error එකක් තමයි මේ. මේකට හේතුව session_start එකට කලින් මොනා හරි content එකක් තිබීම. ඒක space එකක් විතරක් වෙන්නත් පුලුවන්. <?php tag එකට පස්සේ මුලින්ම තියෙන code එක session_start වෙන්න ඕනිි. [PHP]<?php session_start(); ?>[/PHP] [/SIZE][/COLOR] [/QUOTE]
Insert quotes…
Verification
Dawasata paya keeyak thibeda?
Post reply
Top
Bottom