45 lines
1.7 KiB
PHP
45 lines
1.7 KiB
PHP
<?php
|
||
session_start();
|
||
|
||
header('Content-Type: application/json');
|
||
|
||
$questions = [
|
||
"I wake up feeling tired, even after a full night’s sleep.",
|
||
"By midday, I already feel mentally drained and out of energy.",
|
||
"I feel emotionally numb, detached, or ‘on autopilot’ most of the time.",
|
||
"Things that used to excite me now feel pointless or like a chore.",
|
||
"I feel irritated or cynical about people I work or study with.",
|
||
"I struggle to focus and constantly procrastinate, even on important tasks.",
|
||
"I feel guilty for not doing ‘enough’, no matter how much I actually do.",
|
||
"I often think about quitting everything for a while or disappearing from social media and work.",
|
||
"I use caffeine, sugar, nicotine, alcohol, or scrolling to ‘numb out’ instead of resting.",
|
||
"I feel like my life is just surviving, not really living"
|
||
];
|
||
|
||
if (!isset($_SESSION['question_index'])) {
|
||
$_SESSION['question_index'] = 0;
|
||
$_SESSION['answers'] = [];
|
||
}
|
||
|
||
$response = [];
|
||
|
||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||
$data = json_decode(file_get_contents('php://input'), true);
|
||
$answer = $data['answer'] ?? null;
|
||
|
||
if ($answer !== null && $_SESSION['question_index'] < count($questions)) {
|
||
$_SESSION['answers'][$_SESSION['question_index']] = $answer;
|
||
$_SESSION['question_index']++;
|
||
}
|
||
}
|
||
|
||
if ($_SESSION['question_index'] < count($questions)) {
|
||
$response['question'] = $questions[$_SESSION['question_index']];
|
||
} else {
|
||
$response['message'] = 'Thank you for completing the survey! We will provide your results shortly.';
|
||
// Here you could add the logic to analyze the answers and provide recommendations
|
||
session_destroy();
|
||
}
|
||
|
||
echo json_encode($response);
|