Jump to content
bramwolf

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->remove($cursus);

$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

Share this post


Link to post
Share on other sites

Do you really use:

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

rather than:

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

or was that a typo in the post?

Share this post


Link to post
Share on other sites

Or just do

$session->cursus = $page->title;

and

$session->cursus = NULL;

and to retrieve

echo $session->cursus;

Share this post


Link to post
Share on other sites

Yeah I did,

Copied it from the cheatsheet?

http://cheatsheet.processwire.com/session/properties-and-methods/session-set-name-value/

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:

$session->remove('cursus');

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?

http://stackoverflow.com/questions/8247842/session-data-lost-in-chrome-only

http://stackoverflow.com/questions/2953536/randomly-losing-session-variables-only-in-google-chrome-url-rewriting

Share this post


Link to post
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>
 
<script type="text/javascript">      
document.write(getCookie("cursus"));
</script></div>
 
 
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 :)

Share this post


Link to post
Share on other sites

YES!

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

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Mamun Paul
      After upgrade to Processwire 2.8 there is an issue with map markers. It is not compatible and not working correctly like
      1) The sub location map is not displaying on admin on chrome it appears on double click but in Morzilla it works fine.
      2) The sub location pointer gets reset to the default location even after saving.
    • By derelektrischemoench
      Hi guys,
      I'm facing a somewhat strange issue here which I can't quite wrap my head around. 
      I have a PW site in development which runs on three machines simultaneously, one staging server which is accessible as a preview instance for my customer, my PC and my laptop. 
      I have three completely identical settings on each of the three machines (same apache version, same php version, same codebase, same database); however on my PC I am unable to log into the backend. I get no error message or anything, when I try to login; i just get redirected to the login  page. I have already enabled database driven sessions (I enabled them on my laptop, then I dumped the database and copied it to my pc); I have cleared the cache directory; I cleared the sessions in the database; I cleared my browser caches, I tried different browsers, all to no avail; I am unable to login when using my pc, the instances all have the same .htaccess.
      Is there something I'm missing here or does anyone have a clue as to what my issue here might be? I'm using processwire 3.0.123
      Thanks for any input, greetings
      derelektrischemoench
       
      //edit: I've noticed something interesting; despite the directories of my web folders being the same layout; when I open the admin page i get a 404 on the processwire/ resource in the networks panel of chrome; on my laptop I get a  200.... I guess this is where my problem is; but why?
       
       
    • By derelektrischemoench
      Hi guys,
      I'm facing a somewhat strange issue here which I can't quite wrap my head around. 
      I have a PW site in development which runs on three machines simultaneously, one staging server which is accessible as a preview instance for my customer, my PC and my laptop. 
      I have three completely identical settings on each of the three machines (same apache version, same php version, same codebase, same database); however on my PC I am unable to log into the backend. I get no error message or anything, when I try to login; i just get redirected to the login  page. I have already enabled database driven sessions (I enabled them on my laptop, then I dumped the database and copied it to my pc); I have cleared the cache directory; I cleared the sessions in the database; I cleared my browser caches, I tried different browsers, all to no avail; I am unable to login when using my pc, the instances all have the same .htaccess.
      Is there something I'm missing here or does anyone have a clue as to what my issue here might be? I'm using processwire 3.0.123
      Thanks for any input, greetings
      derelektrischemoench
       
       
    • By Peter Knight
      How do you guys handle large session tables when sessions are being recorded to the database?
      I notice one of my sites has a session table of over 14MB 
      Am I missing a way in the Admin or a module to auto-remove any sessions older than X days?
      Thanks
       
    • By helmut2509
      In my PW-Application there is currently no session timeout.
      I want to set the user session to 60 minutes which means that after 60 minutes of inactivity the user will be redirected to the homepage.
      so I added the following entry to my config.php:
      $config->sessionExpireSeconds = 120; (120 seconds is just for testing).
      But after five minutes of inactivity I am still logged in, there is no redirection.
      Is there anything wrong or did I miss something?
      In php.ini I have the entry:
      session.cookie_lifetime = 3600
×
×
  • Create New...