Start New Discussion within our Web Development Community

I have an approve.php inside an /include directory. I have another file inside the /pop_up directory.


if (!isset($_SESSION['username'])) {

When i run the include('include/approve.php') code in files in the main directory, it works. When I run the include('../include/approve.php') in files in the pop_up/ directory it seems to always find that $_SESSION is not set.

Any suggestions?

By default, sessions and cookies start at the root path of the file that created it and all lower sub-folders. Either move your session script at least as high as your other scripts that need it or try to change your session location with session_save_path .

Is there a way to set it to where they can all access session? I create the session in /include, but I need /include and /pop_up to be able to access it.

ALL files must have a session_start() in them (or in their include files) if session variables can be got at.

I assume the popup files (or the files included in them) do not have a session_start().

//EDIT reading that back I don't know if it makes sense.

Best thing to do perhaps is place session_start() at the top of each main file. You don't need session_start in include files if it's already been declared in the main file.

This question has already been answered. Start a new discussion instead.