Search code examples
phphtmlwebfile-structure

Structure of a basic website


So I have been messing around lately with building my own website using MAMP with php, mysql, html, css, etc.. So far, my website has a few different basic pages and a login system that uses mysql and php. Now that I have the login system, I have been including a lot of separate data for a logged in user vs an un-logged in user. I started off by just using php to say:

if(isset($_SESSION['u_id'])) {
    echo "[LOGGED IN DATA HERE]";
} else {
    echo "[LOGGED OUT DATA HERE]";

This worked very well for me for some time but it started to get difficult to be writing so much html inside of the echo statements (without syntax highlighting etc.). The next thing I did was organize my file structure to have different html files in signed_in/signed_out folders and just used this:

if(isset($_SESSION['u_id'])) {
    include "content/signed_in/EXAMPLE.html";
} else {
    include "content/signed_out/EXAMPLE.html";

This started to become difficult though, because I was fiddling with so many different files, and some of them were very similar. The last thing that I tried was using php files instead of html, and filtering for loggedin users and unloggedin users directly in the file, so i could just include it once without having to have so many files, but I ended up with the same issue with the html inside echo. I also have lots of different css files for loggedin/loggedout users. Is there a better way to do this? Should I be using some wort of php framework? Thanks for the help. I am very new to php, html, css, website building, etc..


Solution

  • You can use Laravel php framework. it is really easy to learn and there is good documentation. with laravel you can do the authentication as a middleware so no need to include header files. instead use a middleware to authenticate https://laravel.com/docs/5.6/authentication

    here main benefits of laravel 5 web framework

    • → Develop scalable, feature-rich and secure websites and applications.
    • → Deliver the completed projects within a short period of time. This ensures the long term relationship between you and your clients.
    • → Improving the user experience as much as possible. This happens with the improvement in the security of your website and applications.
    • → Obtain the design and development goals with a little bit of effort.