web 2.0

How to use PHP & Session ($_SESSION,$HTTP_SESSION_VARS)

How to use PHP & Session ($_SESSION,$HTTP_SESSION_VARS) Learn PHP how to using Session and read a php variable , Create Session , Read Session , Delete/Clear Session

ShotDev Focus:
- Create Session
- Read Session
- Delete/Clear Session

Example

php_session1.php (Create Session)


<?
session_start();
$_SESSION["strName"] = "Mr.Weerachai Nukitra";
$_SESSION["strSiteName"] = "ShotDev.Com";
session_write_close();
?>
<html>
<head>
<title>ShotDev.Com Tutorial</title>
</head>
<body>
Session Created.<br><br>
<a href="php_session2.php">Check Session</a>
</body>
</html>

php_session2.php (Read Session)


<?
session_start();
?>
<html>
<head>
<title>ShotDev.Com Tutorial</title>
</head>
<body>
Session Check.<br>
session_id(); = <?=session_id();?><br>
$strName = <?=$_SESSION["strName"];?><br>
$strSiteName = <?=$_SESSION["strSiteName"];?><br>
<br>
<a href="php_session3.php">Delete Session.</a>
</body>
</html>

php_session3.php (Clear Session)


<?
session_start();
//unset($_SESSION["strName"]); // Delete Single Session
//unset($_SESSION["strSiteName"]); // Delete Single Sessionn
session_destroy(); // Delete All Session
?>
<html>
<head>
<title>ShotDev.Com Tutorial</title>
</head>
<body>
Created Check.<br>
$strName = <?=$_SESSION["strName"];?><br>
$strSiteName = <?=$_SESSION["strSiteName"];?><br>
<br>
<a href="php_session1.php">Create Session</a><br>
<a href="php_session2.php">Check Session</a><br>
</body>
</html>

Create a php file and save to path root-path/myphp/

Run
http://localhost/myphp/php_session1.php

Screenshot

PHP Session

PHP Session

PHP Session

.
.
.

Download this script.
Download

1 Star2 Stars3 Stars4 Stars5 Stars6 Stars7 Stars8 Stars9 Stars10 Stars (1 votes, average: 1.00 out of 10)
Loading ... Loading ...

Leave a Reply

You must be logged in to post a comment.