We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,267 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Directory can not access session?

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

Approve.php

if (!isset($_SESSION['username'])) {
	header("location:log_in.php");
	die();
}

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?

4
Contributors
5
Replies
5 Months
Discussion Span
1 Year Ago
Last Updated
6
Views
Question
Answered
megachip04
Light Poster
34 posts since Jul 2011
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 0

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 .

MagicMedia
Junior Poster
149 posts since Jul 2010
Reputation Points: 20
Solved Threads: 35
Skill Endorsements: 0

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.

megachip04
Light Poster
34 posts since Jul 2011
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 0

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.

diafol
Keep Smiling
Moderator
10,666 posts since Oct 2006
Reputation Points: 1,628
Solved Threads: 1,514
Skill Endorsements: 57

thanks. that would not be the first time I have missed that.

megachip04
Light Poster
34 posts since Jul 2011
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 0
Question Answered as of 1 Year Ago by diafol and MagicMedia

Thanks "ardav" and "Magic Media" for your valuable suggestion.

shah01
Newbie Poster
1 post since Feb 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0816 seconds using 2.71MB