Session PHP does not work in different directories

Asked

Viewed 301 times

1

I have a system where the manager directory is as subdomain:

manager.site.com.br

When accessing the manager, a Session is generated as below:

$_SESSION["Logado"] = true;

The session works correctly inside the subdomain, however inside the manager I have a link that directs to the root folder without target:

<a href="http://site.com.br/album/">Álbum de fotos</a>

As I am using jQuery-File-Upload, I put it in the root folder, because when uploading the images, it stores the photos inside the files directory and ends up showing the manager directory. Inside the index.php of the above directory, I call the session again:

session_start();
if($_SESSION["Logado"] == true){
....

The problem is that it seems that when changing directory, the session does not work. Is there any alternative solution? I’ve been thinking of directing to a file called redirect.php in the album folder and recreate the session again and vice versa.

1 answer

0

As it is in a different subdomain it is not found cookies, there are several solutions, can try to put before session_start:

ini_set('session.cookie_domain', '.site.com.br');

If that doesn’t work, try:

session_name('site.com.br');

Browser other questions tagged

You are not signed in. Login or sign up in order to post.