Using Session in PHP

January 27th, 2011 by Nov Piseth Leave a reply »

startsession.php

<?php
session_start();
$sessvar = "dara";
$_SESSION['var']= $sessvar;
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo session_id();?></title>
</head>
<body>
</body>
</html>

viewpage.php

<?php
session_start();
if($_SESSION['var'] == "dara"){
echo "You have rights to visit this page.";
}
else{
echo "You can not access this page.";
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
</body>
</html>
Advertisement

Comments are closed.

WP Facebook Auto Publish Powered By : XYZScripts.com