From 3df594ec1578d7e16ed19516104d3e9c354b1ecb Mon Sep 17 00:00:00 2001 From: BitsHost Date: Sat, 4 Nov 2023 22:20:23 +0200 Subject: [PATCH] init --- .htaccess | 20 ++++++++++++++++++++ Router.php | 23 +++++++++++++++++++++++ Routes.php | 25 +++++++++++++++++++++++++ index.php | 26 ++++++++++++++++++++++++++ pages/404.php | 10 ++++++++++ pages/about.php | 10 ++++++++++ pages/contact.php | 10 ++++++++++ pages/home.php | 10 ++++++++++ 8 files changed, 134 insertions(+) create mode 100644 .htaccess create mode 100644 Router.php create mode 100644 Routes.php create mode 100644 index.php create mode 100644 pages/404.php create mode 100644 pages/about.php create mode 100644 pages/contact.php create mode 100644 pages/home.php diff --git a/.htaccess b/.htaccess new file mode 100644 index 0000000..1f5a25e --- /dev/null +++ b/.htaccess @@ -0,0 +1,20 @@ +Options -Indexes +RewriteEngine on +RewriteCond %{REQUEST_FILENAME} !-d +RewriteCond %{REQUEST_FILENAME} !-f +#RewriteRule ^ - [R=404,L] +#RewriteRule ^ - [R=403,L] + +#ErrorDocument 404 +#ErrorDocument 403 + + +#level One +RewriteRule ^test-([\w\d~%.:_\-]+)$ test?param=$1 [NC] +RewriteRule ^test-([\w\d~%.:_\-]+)/([\w\d~%.:_\-]+)$ test?param=$1&another=$2 [NC] + +#level Two +RewriteRule ^moda-page-([\w\d~%.:_\-]+)$ moda-page?param=$1 [NC] +RewriteRule ^moda-page-([\w\d~%.:_\-]+)/([\w\d~%.:_\-]+)$ test?param=$1&another=$2 [NC] + +RewriteRule (.+) index.php [QSA,L] diff --git a/Router.php b/Router.php new file mode 100644 index 0000000..6595b0e --- /dev/null +++ b/Router.php @@ -0,0 +1,23 @@ +routes[$url] = ['page' => $pageName, 'callback' => $callback]; + } + + // Handle the current request and execute the associated code + public function handle($requestUri) { + foreach ($this->routes as $url => $route) { + if ($url === $requestUri) { + call_user_func($route['callback']); + return; + } + } + + // Handle 404 - Page not found + include 'pages/404.php'; + } +} +?> \ No newline at end of file diff --git a/Routes.php b/Routes.php new file mode 100644 index 0000000..47d8b51 --- /dev/null +++ b/Routes.php @@ -0,0 +1,25 @@ +addRoute('/', 'home', function () { + // Code for the Home page + include 'pages/home.php'; +}); + +$router->addRoute('/about', 'about', function () { + // Code for the About page + include 'pages/about.php'; +}); + +$router->addRoute('/contact', 'contact', function () { + // Code for the Contact page + include 'pages/contact.php'; +}); + +// Handle the current request +$router->handle($_SERVER['REQUEST_URI']); diff --git a/index.php b/index.php new file mode 100644 index 0000000..b5c5e18 --- /dev/null +++ b/index.php @@ -0,0 +1,26 @@ +addRoute('/', 'home', function () { + // Code for the Home page + include 'pages/home.php'; +}); + +$router->addRoute('/about', 'about', function () { + // Code for the About page + include 'pages/about.php'; +}); + +$router->addRoute('/contact', 'contact', function () { + // Code for the Contact page + include 'pages/contact.php'; +}); + +// Handle the current request +$router->handle($_SERVER['REQUEST_URI']); diff --git a/pages/404.php b/pages/404.php new file mode 100644 index 0000000..ac5a446 --- /dev/null +++ b/pages/404.php @@ -0,0 +1,10 @@ + + + + Page Not Found + + +

404 - Page Not Found

+

The page you are looking for does not exist.

+ + diff --git a/pages/about.php b/pages/about.php new file mode 100644 index 0000000..b81098e --- /dev/null +++ b/pages/about.php @@ -0,0 +1,10 @@ + + + + About Page + + +

About Us

+

Learn more about our company and our team.

+ + diff --git a/pages/contact.php b/pages/contact.php new file mode 100644 index 0000000..da9b583 --- /dev/null +++ b/pages/contact.php @@ -0,0 +1,10 @@ + + + + Contact Page + + +

Contact Us

+

Feel free to get in touch with us using the contact information provided.

+ + diff --git a/pages/home.php b/pages/home.php new file mode 100644 index 0000000..57236f0 --- /dev/null +++ b/pages/home.php @@ -0,0 +1,10 @@ + + + + Home Page + + +

Welcome to the Home Page

+

This is the content for the home page.

+ +