<?php
// Start session
session_start();
$action = filter_input(INPUT_POST, 'action');
if ($action === NULL) {
$action = filter_input(INPUT_GET, 'action');
if ($action === NULL) {
$action = 'display_login';
}
}
//instantiate variable(s)
$email = '';
switch ($action) {
case 'display_login':
include('customer_login.php');
break;
case 'display_register':
// If customer is not in the session, set it in the session
if (!isset($_SESSION['customer'])) {
$email = filter_input(INPUT_POST, 'email');
$customer = get_customer_by_email($email);
$_SESSION['customer'] = $customer;
}
?>
Am I able to write this code without using the session_start() function? I have been working to change this without having to use the session_start function but have had a lot of trouble. Is this possible and if so, have I provided enough to do so?
SHORT ANSWER: NO.
Session variables are set with the PHP global variable: $_SESSION
, so you have to use session_start()
to start a session.
If you don't use session_start()
, unless you don't use $_SESSION
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.