Jump to content

Not working $session variables


Recommended Posts

Hey Guys,

I've ran into some really weird behavior with session variables.

What I've been trying to do is this:

I have 10 separate pages that share the same template, named cursus.php.

These are pages with course info and have different title's. these page all

do the following:


$session->set($cursus, $page->title);

They all have a link to one page where you can subscribe for the course

on that page I call out the session variable and want to recall there

from what page they entered the subscription page by doing the following:

 <div>Subscribe for the course: <?PHP echo $session->get($cursus); ?></div> 

and that, on it's turn, gets mailed to my client.

Now Firefox and Safari seem to be displaying the variable perfectly fine but Chrome 

is not. I've tried it on my mobile and and desktop and even in incognito mode, which

should clear any cache problems, but it still doesn't work. 

Am i going about this completely the wrong way or does anyone have a suggestion of

what the problem could be? As you can image it's very important to my client and thus

to me, that I get this working as soon as possible!

Any help will be greatly appreciated.

Bram Wolf

Link to comment
Share on other sites

Yeah I did,

Copied it from the cheatsheet?


I do have the feeling it works? on some browsers? I have no idea what, and why it isn't working properly :P

Well unless you have previously defined $cursus to a value you should end up getting this error:

Notice: Undefined variable: cursus

Although even with that error, it does seem to work ok. I agree with @junofornow - that syntax is much cleaner, although I would use:


Sorry, I am not sure why you are having issues with Chrome - I might be completely off base here, but are either of these any help?



Link to comment
Share on other sites

Hey Guys,

Thanks for the replies! I tried your different syntaxes however with those Firefox, Safari and Chrome failed to display the variable.

I'm not sure how I would define a session variable, other than I did? 

Further I did some testing and read somewhere cookies solved the problem, and cookies also work fine on Firefox and Safari.

But Chrome still doesn't, It sets them properly and gives them the session expiration date but when I go to a different page,

in this case the subscription page, it gets removed from the cookie list. A think Chrome might be doing the same to Processwire's

session variable? I don't know where those are stored but they don't show up in the cookie list.

Has anybody heard of this problem? I set cookies like this:

document.cookie = "cursus=<?PHP echo $page->title ?>; path=/";
and this to retrieve it:
<script type="text/javascript">
function getCookie(name)
    var re = new RegExp(name + "=([^;]+)");
    var value = re.exec(document.cookie);
    return (value != null) ? unescape(value[1]) : null;
<script type="text/javascript">      
Oh btw, When searching Google I keep on finding issues where Chrome doesn't clear the session cookies.. :S
Well at least I fixed that for everyone, my Chrome super-clears cookies :P

Thanx in advance :)

Link to comment
Share on other sites


I fixed it :) On the course-page, where I set the cookie, and the session variable in the first case, I linked to the subscription 

page where in turn I wanted to call the cookie. I figured out that on pretty much all the pages within the site Chrome

kept the cookie alive, except for the subscription page. I saw al links inside my site ended with a slash, checked

the code and saw that the link I made didn't end with the slash.

Also, very weird but I didn't add a domain to the cookie creation, and the course page created a www.domain.com instance

while the subscribe page seemed to be looking for a .domain.com instance, adding a domain to the cookie fixed this as well.

I added it and now chrome keeps the cookie alive :)

Pretty weird that this make so much difference, and that Firefox and Safari don't take the trailing slash into account 

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...