<?php
if (isset($_SESSION)){
session_destroy();
unset($_SESSION);
}
if (session_start() == FALSE) {
$error = 'Please enable cookies, then refresh this page.'
. '<br><br> This error must be resolved before logging in.';
}
?>
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<a href="login.php">Click Here To Login</a>
</body>
</html>
<?php
$env['domain'] = '192.168.2.200';
logout(); //destroy previous sessions.
$lifetime = 60 * 60 * 24; // 24h in seconds
session_set_cookie_params($lifetime, '/', $env['domain'], TRUE, FALSE);
session_start();
$user = array();
$user['id'] = 1;
$user['name'] = 'John';
$_SESSION['user'] = $user;
header('Location: result.php');
function logout(){
//Destroy Session
if (isset($_SESSION)){
session_destroy();
unset($_SESSION);
}
//Delete Sess cookie
$name = session_name();
$expire = strtotime('-1 year');
$params = session_get_cookie_params();
$path = $params['path'];
$domain = $params['domain'];
$secure = $params['secure'];
$httponly = $params['httponly'];
setcookie($name, '', $expire, $path, $domain, $secure, $httponly);
}
?>
<?php
session_start();
print_variable($_SESSION, 'sess');
function print_variable($var, $label, $raw = true){
echo '<br>=========START=========<br>';
echo '<b>' . $label . '</b>';
if ($raw == true) echo '<pre>';
print_r($var);
if ($raw == true) echo '</pre>';
echo '<br>=========END=========<br>';
}
?>
=========START=========
sess
Array
(
)
=========END=========
you only need to do session_start() once.On each page...
ASKER
PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.
TRUSTED BY
ASKER
Open in new window
From my original code, do I still keep lines 8, 23, etc...?