Question: PHP arrays! a. Modify the index.php file so it starts a session that lasts for 1 year. b. Modify the index.php file so it stores
PHP arrays!
a. Modify the index.php file so it starts a session that lasts for 1 year. b. Modify the index.php file so it stores the array of tasks in the session. c. Modify the task_list.php file so it does not store the array of tasks in hidden HTML fields. d. Test this application. Make sure to exit and restart the browser to make sure the session is persistent.
CODE:
index.php
switch( $action ) { case 'add': $new_task = filter_input(INPUT_POST, 'newtask'); if (empty($new_task)) { $errors[] = 'The new task cannot be empty.'; } else { $task_list[] = $new_task; } break; case 'delete': $task_index = filter_input(INPUT_POST, 'taskid', FILTER_VALIDATE_INT); if ($task_index === NULL || $task_index === FALSE) { $errors[] = 'The task cannot be deleted.'; } else { unset($task_list[$task_index]); $task_list = array_values($task_list); } break; }
include('task_list.php'); ?>
task_list.php
Task List Manager
Errors
Tasks
There are no tasks in the task list.
- $task) : ?>
Add Task
0) : ?>
Delete Task
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
