PHP date time, var_dump, include, require, session এর ব্যবহার। এই lesson এ আমরা দেখব কিভাবে PHP তে date-time, var_dump, include, require, session ব্যবহার করতে হয়
Date time:
date_default_timezone_set('Asia/Dhaka');
echo date("Y-m-d h:i:sa");
echo "<br/>";
echo date("d M Y");
echo "<br/>";
echo date("Y-m-d");
var_dump:
$a = 12;
var_dump($a);
$b = true;
var_dump($b);
exit;
echo "<pre>";
$arr = [12, 45, 'gdf'];
var_dump($arr);
echo "</pre>";
Include:
<!DOCTYPE html>
<html>
<head>
<title> This is main page </title>
</head>
<body>
<?php
// require 'page.php';
include 'header.php';
include 'date.php';
?>
</body>
</html>
Require:
<!DOCTYPE html>
<html>
<head>
<title> Another page </title>
</head>
<body>
<?php require 'header.php'; ?>
</body>
</html>
set_session.php
session_start();
$_SESSION['name'] = "My name";
test_session.php
session_start();
if (isset($_SESSION['name'])) {
echo $_SESSION['name'];
} else {
echo 'Please set the session';
}
protected.php:
<?php
session_start();
if (!isset($_SESSION['name'])) {
header('Location: main.php');
}
?>
<!DOCTYPE html>
<html>
<head>
<title> Protected </title>
</head>
<body>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</body>
</html>
session_destroy.php:
session_start();
session_destroy();