1,105,221 Community Members

Sessions Not Working In Another Directory

webdev2012
Newbie Poster
3 posts since Nov 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
Unverified Member
 
0
 

Hello,

So in my root directory sessions work fine. On every page I include an initialization page like so:

<?php include "http://localhost/home/core/init.php";?>

On this page I start the session:

session_start();

Now when logged in to my site I can browse every page in the root directory and still be logged in.

I remain logged in while browsing pages like localhost/home/index.php, localhost/home/about.php etc.

Now when I want to go to a profile page I have to go to another (users) directory:

localhost/home/users/profilepage.php

When I get to this page I am not logged in. I'm presented with a log in form (this is displayed if the user is not logged in).

I have tried things like setting cookie params in the php.ini file to no avail. I have scoured the web endlessly

for days trying to solve this. I need to have many folders/directories on my site and I'm going to need to solve

this soon. I haven't progressed in 3 days and it's very frustrating.

I don't know why it's happening as I'm still including the initialization page that starts the session on the page in the new directory.

I'm fairly new to PHP and programming in general.

Thanks you very much any suggestions are apprectiated.

Member Avatar
GliderPilot
Posting Whiz in Training
295 posts since Sep 2006
Reputation Points: 31 [?]
Q&As Helped to Solve: 48 [?]
Skill Endorsements: 14 [?]
 
0
 

Are you running this on a Windows Server?

webdev2012
Newbie Poster
3 posts since Nov 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
Unverified Member
 
0
 

I am running it on Xammp. Could it be an Xammp configuration issue?

Member Avatar
diafol
Where are my eyes?
12,943 posts since Oct 2006
Reputation Points: 1,821 [?]
Q&As Helped to Solve: 1,845 [?]
Skill Endorsements: 92 [?]
Moderator
Featured
Sponsor
 
0
 

Have you set up virtual hosts, e.g. in your vhosts file:

e.g. C:\xampp\apache\conf\extra\httpd-vhosts.conf

<VirtualHost *:80>
  DocumentRoot c:/xampp/htdocs
  ServerName localhost
</VirtualHost>

<VirtualHost *:80>
  DocumentRoot c:/xampp/htdocs/diafol
  ServerName diafol.local
</VirtualHost>

and then in your hosts file:

e.g. C:\Windows\System32\drivers\etc\hosts

127.0.0.1       localhost
::1             localhost
127.0.0.1       diafol.local

However if everything is in the same parent directory ('home'), can't see why session should fail.

webdev2012
Newbie Poster
3 posts since Nov 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
Unverified Member
 
0
 

No, after making those changes it said I didn't have permission to view the pages so I reverted everything back to normal. Yes everything is contained within Home but when going to the new directory ('users') the session is lost, so frustrating.

Member Avatar
GliderPilot
Posting Whiz in Training
295 posts since Sep 2006
Reputation Points: 31 [?]
Q&As Helped to Solve: 48 [?]
Skill Endorsements: 14 [?]
 
0
 

Just off the top of my head, if you're running Xammp on Windows you may have to change a couple session settings in your php.ini file:

session.save_path = c:\temp
session.cookie_path = /

If it's still not working it may have to do with the fact you're using localhost which has a very refined set of rules that can cause issues like the one you're having.You can't techinically set a proper cookie on a non registry controlled domain. You could always try using the hosts file to setup a fake "proper" domain like mytest.local which should work in everything but Chrome

Member Avatar
veedeoo
Veteran Poster
1,009 posts since Oct 2011
Reputation Points: 314 [?]
Q&As Helped to Solve: 164 [?]
Skill Endorsements: 17 [?]
 
0
 

Hi,

think of it as
localhost/ root account
localhost/domainOne/ session is only effective here and nowhere else
localhost/domainTwo/ the same thing here, session cannot be validated above this directory and below this directory

while sessions stablished, in these directories are valid in directory domainOne

localhost/domainOne/directoryone/
localhost/domainOne/directorytwo/
and the list goes on....

So, session from directory domainOne cannot be valid in domainTwo directory. It works like a VPS hosting with multiple domains in it.. sessions are processed only specific to its own working directory, space, or domain.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article