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:


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:


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.

Recommended Answers

All 6 Replies

Are you running this on a Windows Server?

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

Member Avatar

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 *:80>
  DocumentRoot c:/xampp/htdocs/diafol
  ServerName diafol.local

and then in your hosts file:

e.g. C:\Windows\System32\drivers\etc\hosts       localhost
::1             localhost       diafol.local

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

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.

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


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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.