I am very new to php and have been hammering google for as much information as I can find but have discovered that online tutorials never seem to explain things in a way that I understand.
If for example I have a page that people see when they are not logged in, should this be its own php file with its own html or should I just be displaying different content with php when they are signed in in the same index.php file.
I hope this makes sense.
The reason that I ask is because I have noticed that many php websites do not show changes in the url when navigating to different pages. I have experienced this with âheaderâ - showing a new php file after clicking a button. I would image it depends what I âwant to doâ but I am looking for advice.
Should I be using href with different pages or is the header something that I need to look into.
A lot of the websites are using what they refer as clean URLs, they are probably going to actual webpages but it doesnât seem like it. Itâs good practice to redirect people who are not logged in to a non-member page (usually a separate page).
Yeah you would store the logged in userâs data in the session, then from your php check this is set and redirect to the login page if not. If youâre working with separate files for each page then you can have a common include file that does that operation. Pages with clean urls use a router mechanism and they are always hitting index.php parsing the url and giving you the appropriate content. Having your own routing mechanism is very powerful and better architecture. It means you donât need to have includes per every file and can have common code called from index.php
I would go for the same index page with different content. This can be done by including the different content into the same page as I assume the header footer etc. would be common. You could check if the user is logged in or not and display the relevant information.
I tend to use my own âtemplatingâ system and have a common header, navigation and footer. Depending on the URL different content is included. I sometimes have a rewrite rule to change a php page with a variable into a URL with an html extension.
This also works well as if you add or remove pages you only need to alter the navigation code in one file rather than the navigation code on every page.