Sebastian Opperman
Sebastian Opperman

Reputation: 241

Use Session in Parent Folder in PHP

I have 2 folders/directories:

login/helper.php
dashboard/index.php

I have set a session in helper.php in the login folder. I am trying to retrieve a session on the index page in the dashboard folder. Somehow i cannot retrieve the session in another folder or a parent directory.

Here is the Code on the login/helper.php

session_start();
$_SESSION['userID'] = $checklogin['userID'];

Here is the code on the dashboard/index.php

echo $_SESSION['userID'];

Is there a way to make a session available in a parent directory and all it's folders?

Kind Regards

Upvotes: 1

Views: 866

Answers (2)

chandresh_cool
chandresh_cool

Reputation: 11830

In your case looks like you need to add session_start() at the starting of your file.

But as per coding standards I would suggest to put that session_start() in a common file and may be try to include that file in your all pages, that way you don't need to include session_start(0) everywhere.

Upvotes: 0

Borgtex
Borgtex

Reputation: 3245

Just start the session again in dashboard/index.php:

session_start();
echo $_SESSION['userID'];

Upvotes: 1

Related Questions