Example file: index.php
In the previous examples, we edit the About page by specifying the filename:
$filename = 'about';
In our CMS, we remove this line and use .htacess file to perform a URL rewriting. With URL rewriting, you can type in your browser: http://localhost/about and our PHP page will see it as:
index.php?f=about
So we can get the filename of the page we want to open by using:
$filename = $_GET['f'];
Now we can move to our simple CMS. If you check the main file index.php, you will see that it basically uses all the code as explained in the step 1 – 8, plus some added small but important features, such as: menu, account and site settings for uploading logo and favicon. One last thing that needs to be explained is about URL rewriting feature.
To achieve this, in the .htaccess file, we add the following line:
RewriteRule ^([A-Za-z0-9-_]+)/?$ index.php?f=$1&$2 [NC,L,QSA]
You can also see in our .htaccess file other rewriting rules for our login.php and logout.php page, so that you can access the login and logout page using:
http://localhost/login
http://localhost/logout
That’s all the main things we use for our simple CMS project. We put all the main code in the index.php file so that you can see how it works based on our step-by-step examples.
http://localhost/mysite/
Our simple CMS with some improvement features: Menu, Account & Site Settings.
About | Privacy | Delivery & Return
Copyright © 2021 Insite Mitra Inovindo. All Rights Reserved.