Skip to content

Commit 2334c6b

Browse files
committed
Feat: CORS handling function implemented
1 parent c90457b commit 2334c6b

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

src/App.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,16 @@ public static function is_csrf_valid()
8080
return isset($_SESSION['csrf']) && isset($request['csrf'])
8181
&& $_SESSION['csrf'] == $request['csrf'];
8282
}
83+
84+
public static function handle_cors()
85+
{
86+
header('Access-Control-Allow-Origin: *');
87+
header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS');
88+
header('Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With');
89+
header('Access-Control-Max-Age: 86400'); // 24 hours
90+
91+
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
92+
exit(0);
93+
}
94+
}
8395
}

0 commit comments

Comments
 (0)