1. <?php
  2. // Configuration
  3. $rate_limit = 10; // Requests per minute
  4. $rate_limit_window = 60; // Time window in seconds
  5. // Session for tracking requests
  6. session_start();
  7. // Function to check rate limit
  8. function isRateLimited() {
  9. global $rate_limit, $rate_limit_window;
  10. if (!isset($_SESSION['request_count'])) {
  11. $_SESSION['request_count'] = 0;
  12. }
  13. if (($_SESSION['request_count'] >= $rate_limit) && (time() - $_SESSION['last_reset'] < $rate_limit_window)) {
  14. return true; // Rate limited
  15. } else {
  16. $_SESSION['request_count']++;
  17. $_SESSION['last_reset'] = time();
  18. return false; // Not rate limited
  19. }
  20. }
  21. // Function to generate nested HTML structures
  22. function generateNestedHTML($depth, $content) {
  23. $html = '';
  24. for ($i = 0; $i < $depth; $i++) {
  25. $html .= '<div>'; // Create a div for each level of nesting
  26. $html .= $content;
  27. $html .= '</div>';
  28. }
  29. return $html;
  30. }
  31. // Example usage - diagnostic page
  32. if ($_SERVER["REQUEST_METHOD"] == "GET") {
  33. if (isRateLimited()) {
  34. header("HTTP/1.1 429 Too Many Requests");
  35. echo "<h1>Too many requests. Please try again later.</h1>";
  36. exit;
  37. }
  38. $depth = isset($_GET['depth']) ? intval($_GET['depth']) : 2; // Get depth from URL, default to 2
  39. $content = "<h1>Diagnostic Page</h1><p>This is a diagnostic page. Depth: " . $depth . "</p>";
  40. $nested_html = generateNestedHTML($depth, $content);
  41. echo '<!DOCTYPE html>';
  42. echo '<html lang="en">';
  43. echo '<head>';
  44. echo '<meta charset="UTF-8">';
  45. echo '<title>Diagnostic Page</title>';
  46. echo '<style>';
  47. echo 'div { border: 1px solid black; margin: 10px; padding: 10px; }';
  48. echo '</style>';
  49. echo '</head>';
  50. echo '<body>';
  51. echo $nested_html;
  52. echo '</body>';
  53. echo '</html>';
  54. } else {
  55. echo "Invalid request method.";
  56. }
  57. ?>

Add your comment