class Page { private $url; public function __construct() { $this->url = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; } public function getUrl() { return $this->url; } } $page = new Page(); echo $page->getUrl(); // outputs "https://example.com/page.php"
class Redirect { public static function to($url) { header('Location: ' . $url); exit(); } } Redirect::to('https://example.com/home.php');This example shows how to redirect the user to a different page by using the header function and setting the Location header to the desired URL. The exit function is called to ensure that no further script execution occurs. Package library: This code does not use any package libraries.