Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Themes & Styling

Why can't I access PHP session data from theme PHP file?

Started by O 4 years ago · 1 replies · 793 views
4 years ago

How do I access session variables that were set outside of Grav CMS?

In my user system.yaml file I have set the following:
session:
enabled: true
initialize: true
timeout: 3600
name: gravsite
uniqueness: path
secure: false
httponly: true
samesite: Strict

Within my theme folder I have a mythemename.php file which contains the following:
<?php
print_r($_SESSION);
?>

But this gives me an empty array response. If I browse back to my code outside of Grav, I can see the session variables are still set but it seems when I am in Grav, I am unable to access them. How do I get around this?

Both my application outside of Grav and Grav CMS are all in the same web server and running on the same domain - I have the whole of Grav CMS files in a subfolder.

4 years ago

@thisisready, Cross-posting the same question on multiple forums a few minutes apart is not really considerate to other people's time spend...

...keep in mind that this is not generally in the interests of the posters who might be responding to your posts - those folks may find they've wasted their time. You certainly don't want to annoy those you want to help you, so you might want to make the experience as painless as possible.
The best way to do something like this (without ticking people off) would be to let people know upfront that the crossposting is occurring. This makes the most sense if there's a respectable delay between posting in one forum and another, e.g:
"I posted this question the other day in SomeOtherForum.com [link], but wasn't able to get a good answer, so now I'm asking here..."
A responsible netizen might also post a followup in SomeOtherForum.com letting people there know if a better answer is found.

https://meta.stackexchange.com/a/141824

last edited 01/05/22 by pamtbaau

Suggested topics

Topic Participants Replies Views Activity
Themes & Styling · by Pedro M, 2 months ago
4 224 2 months ago
Themes & Styling · by Ian, 2 months ago
3 118 2 months ago
Themes & Styling · by Norbert, 2 years ago
11 481 3 months ago
Themes & Styling · by Lukáš Findeis, 3 months ago
0 72 3 months ago
Themes & Styling · by Sebadamus, 4 months ago
5 152 3 months ago