setting php sesssion
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||
zoom.php
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||
<?php
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||
$title = '<h1> telugu computer world </h1>';
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||
$title2 = '<h1> php </h1>';
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||
?>
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||
page1
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||
<?php
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||
include 'zoom.php';
|
after adds this include like bootstrap, we can access that
template data
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
echo $title2;
|
print that title2
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
?>
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||
how to store the information in user browser
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||
set.php
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||
<?php
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||
session_start();
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||
$_SESSION['name'] = 'rafique';
|
variable name (key) - load that value
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
?>
|
aftere this page open, if u open vies.php
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
whenever this page opens, this cookies store in user browser
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||
view .pjp
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||
<?php
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||
session_start();
|
after sesion start only that cookei will execute
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
echo = $_SESSION['name'];
|
if that set.php page opens, then if u open this page view page
that prints the name called
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
?>
|
rafique
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| session1.php
<?php
session_start();
?>
<html>
<body>
<?php
$_SESSION["user"] = "Sachin";
echo "Session information are set successfully.<br/>";
?>
<a href="session2.php">Visit next page</a>
</body>
</html>
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||
| session2.php
<?php
session_start();
?>
<html>
<body>
<?php
echo "User is: ".$_SESSION["user"];
?>
</body>
</html>
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||
how to know how many times customer visited the page
using session_start- started to store the cookies in
customer browser, if session started ,means it is set, counter increment,if u
see so many times, it will increment and tells, how many times u browse
Live
Demo
<?php
session_start();
if( isset( $_SESSION['counter'] ) ) {
$_SESSION['counter'] += 1;
}else {
$_SESSION['counter'] = 1;
}
$msg = "You have visited
this page ". $_SESSION['counter'];
$msg .= "in this
session.";
?>
<html>
<head>
<title>Setting up a PHP session</title>
</head>
<body>
<?php echo ( $msg ); ?>
</body>
</html>
If session is started
Lifetime of cookie -'cookie_lifetime' => 86400,
Storing or loading some data to
sessions
$_SESSION['favcolor'] = 'green';
$_SESSION['animal'] = 'cat'; $_SESSION['time'] = time();
Shown to some other page
<?php // Starting session session_start(); // Accessing session data echo
'Hi, ' . $_SESSION["firstname"] . ' ' . $_SESSION["lastname"]; ?>
echo $_SESSION['favcolor']; // green
echo $_SESSION['animal']; // cat echo date('Y m d H:i:s', $_SESSION['time']);
Destroys the session
PHP session_destroy() function is used to destroy all session variables completely.
<?php // Starting session session_start(); // Destroying session session_destroy(); ?>
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||
| include |
| echo |
| session_start() |
| $_SESSION['NAME'] |
| session_start |
| $_SESSION['NAME'] |
No comments:
Post a Comment