group-icon
PHP Programming
Group for all things PHP, Coding Help, Problems and Solutions
104 Members
Join this group to post and comment.
Naveen Sunil
Naveen Sunil
Information Technology
04 Jan 2019

Persistent DB session across subfolders

Ok I have a login page inside a directory with a sub folder. Now the session handler consists of database connection. When I go to one sub folder and from there inside a php file I call the session file from one level above as inlcude '../sessions.php' ; but it looks like I could use all variables from the sessions file but the database doesn't connect here and as a result the sql command doesn't execute inside the current file.

For reference this is the document folders tree.

/home

    /includes

        /config.php      ---> Database connection

    /folder

        /index.php       ---> include 'session.php'

        /login.php        ---> include '../includes/config.php'

        /session.php   ---> include '../includes/config.php'

        /subfolder

            /index.php   ---> include '../session.php'       /*Here I couldn't access the database until I include the config.php directly here*/


Sorry for the complex explanation!

Rohit Kumar
Rohit Kumar
Electronic
3mos ago

This is interesting. My guess is that because there there is a second level nesting involved the session loses its data. Check if you are correctly using session_start() in each of your files.

3mos ago

Has your problem been addressed? 

Naveen Sunil
Naveen Sunil
Information Technology
3mos ago

session_start() is all fine. But doesn't work. I could make it work by adding the config file into to subfolder. But it doesn't inherit from sessions file.

I could also make it work by creating a function and calling it.