thetuningspoon

Session variable getting lost after $session->redirect()

Recommended Posts

Hi all,
I'm setting a PW session variable in a module for an error message to output later in my template. The message is not appearing in my template, and I've narrowed it down to the fact that I am doing a $session->redirect("./") to reload the page after setting the value using $session->error = "my error message". If I use the php $_SESSION superglobal or if I remove the redirect, it works fine. But PW's $session should persist after a redirect, so I'm not sure what's going on here.

EDIT:

By the way, I'm using 2.5. Also, just realized that I'm getting this warning message: 

Warning: Invalid argument supplied for foreach() in /wire/core/Session.php on line 79

  • Like 1

Share this post


Link to post
Share on other sites

Sorry, but I don't think the specific code would be helpful in this case. It's spread out, and the part that has to do the actual issue is what I've explained above. If it's not something apparent to anyone, I'll keep hacking away at it or settle for using $_SESSION.

Share this post


Link to post
Share on other sites

I have had some similar issue and hacked around them also. Never really tried to figure out the root cause or come up with something that was repeatable enough to report.

Share this post


Link to post
Share on other sites

Hi Guys,

I think I finally solved this :) Or at least, I solved it for my case. The problem I had with this was that I used a form

which submitted the page to a "www." variant of the page while all other standard pages where rendered without the 

"www.". By changing this in the config.php file I was able to keep all session variables and cookies (which previously also got dropped)

$config->httpHosts = array(
  'processwire.com', // our primary hostname
  'www.processwire.com', // alternate hostname
  'dev.processwire.com', // staging server
  'localhost:8888' // MAMP local dev server
  );

I changed the one first to a www. variant, and the second one to a non-www. variant. in /site/config.php

I hope this helps someone in the future! :)

Bram

  • Like 2

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.