Question: in php I need to add the code for a session cookie that persists for three years to the index.php page. I also need to
in php I need to add the code for a session cookie that persists for three years to the index.php page. I also need to Clean up session ID Delete the cookie for the session Get name of the session cookie, Create expiration date in the past and Get session params code is below :
Index.php:
//Add a cookie that is persistent for 3 years.
// Add fields with optional initial message $validate = new Validate(); $fields = $validate->getFields(); $fields->addField('first_name'); $fields->addField('last_name'); $fields->addField('phone', 'Use 888-555-1234 format.'); $fields->addField('email', 'Must be a valid email address.');
$action = filter_input(INPUT_POST, 'action'); if ($action === NULL) { $action = 'reset'; } else { $action = strtolower($action); }
switch ($action) { case 'reset': // Reset values for variables $first_name = ''; $last_name = ''; $phone = ''; $email = '';
// Load view include 'view/register.php'; break; case 'register': // Copy form values to local variables $first_name = trim(filter_input(INPUT_POST, 'first_name')); $last_name = trim(filter_input(INPUT_POST, 'last_name')); $phone = trim(filter_input(INPUT_POST, 'phone')); $email = trim(filter_input(INPUT_POST, 'email'));
// Validate form data $validate->text('first_name', $first_name); $validate->text('last_name', $last_name); $validate->phone('phone', $phone); $validate->email('email', $email);
// Load appropriate view based on hasErrors if ($fields->hasErrors()) { include 'view/register.php'; } else { include 'view/success.php'; } // Clean up session ID // Delete the cookie for the session // Get name of the session cookie // Create expiration date in the past // Get session params break; } ?>
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
