Difference between revisions for Users / Eo Ny / dev
| Version1 | Version2 | ||
|---|---|---|---|
| 41 | ---- | 41 | ---- |
| 42 | === Constructor === | 42 | === Constructor === |
| 43 | 43 | ||
| 44 |
%% |
44 | %%(hl php) |
| 45 | public function __construct(&$db) | 45 | public function __construct(&$db) |
| 46 | %% | 46 | %% |
| 47 | 47 | ||
| … | … | … | … |
| 59 | 6. Enforces TLS session upgrade if needed | 59 | 6. Enforces TLS session upgrade if needed |
| 60 | 60 | ||
| 61 | **Example:** | 61 | **Example:** |
| 62 |
%% |
62 | %%(hl php) |
| 63 | $http = new Http($db); | 63 | $http = new Http($db); |
| 64 | %% | 64 | %% |
| 65 | 65 | ||
| … | … | … | … |
| 83 | - Recovers diagnostic logs from previous session | 83 | - Recovers diagnostic logs from previous session |
| 84 | 84 | ||
| 85 | **Example:** | 85 | **Example:** |
| 86 |
%% |
86 | %%(hl php) |
| 87 | $http->session(0); // Normal session | 87 | $http->session(0); // Normal session |
| 88 | $http->session(2); // Static file serving mode | 88 | $http->session(2); // Static file serving mode |
| 89 | %% | 89 | %% |
| … | … | … | … |
| 106 | - ✅ Only cached for anonymous users (no logged-in users) | 106 | - ✅ Only cached for anonymous users (no logged-in users) |
| 107 | 107 | ||
| 108 | **Example:** | 108 | **Example:** |
| 109 |
%% |
109 | %%(hl php) |
| 110 | $http->check_cache('HomePage', 'show'); | 110 | $http->check_cache('HomePage', 'show'); |
| 111 | %% | 111 | %% |
| 112 | 112 | ||
| … | … | … | … |
| 145 | 4. Returns count of invalidated caches | 145 | 4. Returns count of invalidated caches |
| 146 | 146 | ||
| 147 | **Example:** | 147 | **Example:** |
| 148 |
%% |
148 | %%(hl php) |
| 149 | $count = $http->invalidate_page('HomePage'); | 149 | $count = $http->invalidate_page('HomePage'); |
| 150 | echo "Invalidated $count cache entries"; | 150 | echo "Invalidated $count cache entries"; |
| 151 | %% | 151 | %% |
| … | … | … | … |
| 163 | - Called when TLS session is detected | 163 | - Called when TLS session is detected |
| 164 | 164 | ||
| 165 | **Example:** | 165 | **Example:** |
| 166 |
%% |
166 | %%(hl php) |
| 167 | $http->secure_base_url(); | 167 | $http->secure_base_url(); |
| 168 | // $db->base_url now uses https:// | 168 | // $db->base_url now uses https:// |
| 169 | %% | 169 | %% |
| … | … | … | … |
| 182 | - Converts relative URLs using current server name | 182 | - Converts relative URLs using current server name |
| 183 | 183 | ||
| 184 | **Example:** | 184 | **Example:** |
| 185 |
%% |
185 | %%(hl php) |
| 186 | $http->ensure_tls('/secure/payment'); | 186 | $http->ensure_tls('/secure/payment'); |
| 187 | %% | 187 | %% |
| 188 | 188 | ||
| … | … | … | … |
| 210 | - ##reverse_proxy_header## - Custom header name (default: ##X-Forwarded-For##) | 210 | - ##reverse_proxy_header## - Custom header name (default: ##X-Forwarded-For##) |
| 211 | 211 | ||
| 212 | **Example:** | 212 | **Example:** |
| 213 |
%% |
213 | %%(hl php) |
| 214 | $client_ip = $http->ip; // e.g., "203.0.113.42" | 214 | $client_ip = $http->ip; // e.g., "203.0.113.42" |
| 215 | %% | 215 | %% |
| 216 | 216 | ||
| … | … | … | … |
| 254 | - ##2## - Custom policy (from ##csp_custom.conf##) | 254 | - ##2## - Custom policy (from ##csp_custom.conf##) |
| 255 | 255 | ||
| 256 | **Example:** | 256 | **Example:** |
| 257 |
%% |
257 | %%(hl php) |
| 258 | $http->http_security_headers(); | 258 | $http->http_security_headers(); |
| 259 | %% | 259 | %% |
| 260 | 260 | ||
| … | … | … | … |
| 274 | - Uses output buffering to work anywhere in page processing | 274 | - Uses output buffering to work anywhere in page processing |
| 275 | 275 | ||
| 276 | **Example:** | 276 | **Example:** |
| 277 |
%% |
277 | %%(hl php) |
| 278 | $http->redirect('http://example.com/new-page', true); // 301 | 278 | $http->redirect('http://example.com/new-page', true); // 301 |
| 279 | $http->redirect('/wiki/HomePage'); // 302 | 279 | $http->redirect('/wiki/HomePage'); // 302 |
| 280 | %% | 280 | %% |
| … | … | … | … |
| 289 | - Ends script execution | 289 | - Ends script execution |
| 290 | 290 | ||
| 291 | **Example:** | 291 | **Example:** |
| 292 |
%% |
292 | %%(hl php) |
| 293 | $http->terminate(); | 293 | $http->terminate(); |
| 294 | %% | 294 | %% |
| 295 | 295 | ||
| … | … | … | … |
| 299 | Sets HTTP response status code. | 299 | Sets HTTP response status code. |
| 300 | 300 | ||
| 301 | **Supported Status Codes:** | 301 | **Supported Status Codes:** |
| 302 |
%% |
302 | %%(hl php) |
| 303 | 200 => 'OK' | 303 | 200 => 'OK' |
| 304 | 206 => 'Partial Content' | 304 | 206 => 'Partial Content' |
| 305 | 301 => 'Moved Permanently' | 305 | 301 => 'Moved Permanently' |
| … | … | … | … |
| 319 | %% | 319 | %% |
| 320 | 320 | ||
| 321 | **Example:** | 321 | **Example:** |
| 322 |
%% |
322 | %%(hl php) |
| 323 | $http->status(404); // Send 404 Not Found | 323 | $http->status(404); // Send 404 Not Found |
| 324 | %% | 324 | %% |
| 325 | 325 | ||
| … | … | … | … |
| 340 | - ##Cache-Control: no-store## | 340 | - ##Cache-Control: no-store## |
| 341 | 341 | ||
| 342 | **Example:** | 342 | **Example:** |
| 343 |
%% |
343 | %%(hl php) |
| 344 | $http->no_cache(); // Client-side only | 344 | $http->no_cache(); // Client-side only |
| 345 | $http->no_cache(false); // Both client & server | 345 | $http->no_cache(false); // Both client & server |
| 346 | %% | 346 | %% |
| … | … | … | … |
| 354 | - ##Cache-Control: public## | 354 | - ##Cache-Control: public## |
| 355 | 355 | ||
| 356 | **Example:** | 356 | **Example:** |
| 357 |
%% |
357 | %%(hl php) |
| 358 | $http->cache_promisc(); | 358 | $http->cache_promisc(); |
| 359 | %% | 359 | %% |
| 360 | 360 | ||
| … | … | … | … |
| 399 | - Associative array: ##['en' => 'en', 'de' => 'de', ...]## | 399 | - Associative array: ##['en' => 'en', 'de' => 'de', ...]## |
| 400 | 400 | ||
| 401 | **Example:** | 401 | **Example:** |
| 402 |
%% |
402 | %%(hl php) |
| 403 | $all_langs = $http->available_languages(false); | 403 | $all_langs = $http->available_languages(false); |
| 404 | $allowed = $http->available_languages(true); | 404 | $allowed = $http->available_languages(true); |
| 405 | %% | 405 | %% |
| … | … | … | … |
| 425 | - GZip compression for text files | 425 | - GZip compression for text files |
| 426 | 426 | ||
| 427 | **Special Paths:** | 427 | **Special Paths:** |
| 428 |
%% |
428 | %%(hl php) |
| 429 | $http->sendfile(404); // Serves file defined by HTTP_404 constant | 429 | $http->sendfile(404); // Serves file defined by HTTP_404 constant |
| 430 | $http->sendfile(403); // Serves file defined by HTTP_403 constant | 430 | $http->sendfile(403); // Serves file defined by HTTP_403 constant |
| 431 | %% | 431 | %% |
| 432 | 432 | ||
| 433 | **Example:** | 433 | **Example:** |
| 434 |
%% |
434 | %%(hl php) |
| 435 | $http->sendfile('uploads/document.pdf', 'my-document.pdf', 30); | 435 | $http->sendfile('uploads/document.pdf', 'my-document.pdf', 30); |
| 436 | %% | 436 | %% |
| 437 | 437 | ||
| … | … | … | … |
| 445 | - Default: ##'application/octet-stream'## | 445 | - Default: ##'application/octet-stream'## |
| 446 | 446 | ||
| 447 | **Example:** | 447 | **Example:** |
| 448 |
%% |
448 | %%(hl php) |
| 449 | $mime = $http->mime_type('file.pdf'); // 'application/pdf' | 449 | $mime = $http->mime_type('file.pdf'); // 'application/pdf' |
| 450 | %% | 450 | %% |
| 451 | 451 | ||
| … | … | … | … |
| 475 | - Headers not already sent | 475 | - Headers not already sent |
| 476 | 476 | ||
| 477 | **Example:** | 477 | **Example:** |
| 478 |
%% |
478 | %%(hl php) |
| 479 | $http->gzip(); | 479 | $http->gzip(); |
| 480 | %% | 480 | %% |
| 481 | 481 | ||
| … | … | … | … |
| 491 | - Converts encoding properly | 491 | - Converts encoding properly |
| 492 | 492 | ||
| 493 | **Example:** | 493 | **Example:** |
| 494 |
%% |
494 | %%(hl php) |
| 495 | $data = $http->parse_str('name=John&age=30'); | 495 | $data = $http->parse_str('name=John&age=30'); |
| 496 | %% | 496 | %% |
| 497 | 497 | ||
| … | … | … | … |
| 597 | 597 | ||
| 598 | ==== Example 2: Handling TLS/HTTPS Upgrade ==== | 598 | ==== Example 2: Handling TLS/HTTPS Upgrade ==== |
| 599 | 599 | ||
| 600 |
%% |
600 | %%(hl php) |
| 601 | $http = new Http($db); // Constructor detects TLS requirement | 601 | $http = new Http($db); // Constructor detects TLS requirement |
| 602 | // If TLS is enabled and user wasn't in TLS before: | 602 | // If TLS is enabled and user wasn't in TLS before: |
| 603 | // - Sets TLS session flag | 603 | // - Sets TLS session flag |
| … | … | … | … |
| 607 | 607 | ||
| 608 | ==== Example 3: Invalidating Cache After Page Edit ==== | 608 | ==== Example 3: Invalidating Cache After Page Edit ==== |
| 609 | 609 | ||
| 610 |
%% |
610 | %%(hl php) |
| 611 | // User edits a page | 611 | // User edits a page |
| 612 | $http = new Http($db); | 612 | $http = new Http($db); |
| 613 | $count = $http->invalidate_page('HomePage'); | 613 | $count = $http->invalidate_page('HomePage'); |
| … | … | … | … |
| 616 | 616 | ||
| 617 | ==== Example 4: Serving a File ==== | 617 | ==== Example 4: Serving a File ==== |
| 618 | 618 | ||
| 619 |
%% |
619 | %%(hl php) |
| 620 | $http = new Http($db); | 620 | $http = new Http($db); |
| 621 | $http->session(2); // Static file mode - no session replay prevention | 621 | $http->session(2); // Static file mode - no session replay prevention |
| 622 | 622 | ||
| … | … | … | … |
| 691 | 691 | ||
| 692 | The class integrates with WackoWiki's diagnostic system: | 692 | The class integrates with WackoWiki's diagnostic system: |
| 693 | 693 | ||
| 694 |
%% |
694 | %%(hl php) |
| 695 | // Diagnostic messages are preserved across redirects | 695 | // Diagnostic messages are preserved across redirects |
| 696 | // via session flash data | 696 | // via session flash data |
| 697 | 697 | ||