0

I have this code where a user that is logged in, gets a specific page from the 'views' folder (protected by htaccess). Only when logged in can you grant access to the page. Here is an example of the code

if ($login->isUserLoggedIn() == true) {
    include("views/page_to_show.php");

} else {
    //I simply show the "you are not logged in" view.
    include("views/not_logged_in.php");
}

This works. The thing is though, I want to organise my pages a little more. So I want to move a couple of pages to a folder within the views folder.

So for example:

if ($login->isUserLoggedIn() == true) {
    include("views/folder/page_to_show.php");

} else {
    //I simply show the "you are not logged in" view.
    include("views/not_logged_in.php");
}

The script can be found on mydomain.com/folder/page_to_show.php but when I try to open it, I am not getting the page from the views folder, neither getting anything like an error. Just a blank page. Does anyone know what is happening and why I can not organise my pages like this?

Nour
  • 143
  • 1
  • 15
  • 1
    [Are errors enabled? if not, enable them.](https://stackoverflow.com/questions/1475297/phps-white-screen-of-death) what is the path for your PHP file (the one that you are posting in the question)? – Spoody Mar 12 '18 at 20:13
  • where is the views folder located? – nitrex Mar 12 '18 at 20:14
  • The path to the PHP script is for an example mydomain.com/folder/page_to_show.php. This page contains the script above. The views folder is located mydomain.com/views/ but cannot be accessed directly, you need an include that can be found on mydomain.com/folder/page_to_show.php for an example – Nour Mar 12 '18 at 20:19
  • The problem is, I think, that all paths are relative. Which means that it will be looking for the views folder within the 'folder' in my example. It's not there of course, because it's in the main directory. How can I fix this? How can I include the page in the original views page? – Nour Mar 12 '18 at 20:31
  • 1
    so use relative paths, use "../" to go back a level if needed – nitrex Mar 12 '18 at 20:33
  • So when I am in mydomain.com/folder/file.php and I want to include a file from mydomain.com/views/ I need to link: "../views/page.php" ? – Nour Mar 12 '18 at 20:36
  • I tried and it worked. Thanks for your help. – Nour Mar 12 '18 at 20:38

0 Answers0