1

I have a custom module that subscribes to an event called catalog_product_collection_apply_limitations_after. In the observer I am setting a variable (E.g $_GET['test'] = true)

Then later in my .phtml file I am accessing that to do logic based on the variable. It works well, however, once launched on one of our client's webshop, all the globals like $_GET, $_POST, $_REQUEST appears empty.

My guess is that there is a redirect happening, but then I ask myself why in the world would someone do that, as it definitely messes up most 3rd party extensions. But I might be wrong though.

Any other ideas of why would this be happening ?

P.S Here's a subset of var dump of $GLOBALS variable in the frontend:

array(16) { ["_GET"]=> array(1) { ["limit"]=> string(2) "12" } ["_POST"]=> array(0) { }

0

I think the using of the $_SESSION global variable is solution for you, because after the redirect your server drops all of the $_REQUEST variables.

Here is answer for similar problem:

Global variables are not persistent between http requests, like a redirect. You have to use a session to store this data between requests.

| improve this answer | |
  • I really hate the sessions as I will have to clear my variables after they are read, but I guess there's no other option. P.S Do you have any idea why would someone be doing these redirects? Is there a purpose? Security issue or whatever? – Emke Aug 8 '16 at 13:06
  • @Emke You should deeply research this problem. In my opinion it's bug or just a bad code. – Siarhey Uchukhlebau Aug 8 '16 at 13:12
  • @Emke Well written redirect should save all request data, because you can transfer through it the product id or other important information. – Siarhey Uchukhlebau Aug 8 '16 at 13:16
  • ok, thanks for the info. I will forward the issue towards the shop's developers. Meanwhile, I will hard code the module to use sessions for them. Thanks – Emke Aug 8 '16 at 13:25
1

I'd advise using the Magento registry rather than setting values using the GET variable.

// Set the registry value
Mage::register('test', TRUE);

// Gets the registry value
$registryValue = Mage::registry('test');

Of course, if it is redirecting your request then this also won't work :)

| improve this answer | |
  • exactly, as there's a redirect happening, I can't use that either. And I need the variable to be request scope (and read it on the frontend). I don't feel like using sessions and deleting the variables once I read them, sounds like too much overhead – Emke Aug 8 '16 at 12:47
  • Right solution. Direct use of a of global variables is not a good practice. – Siarhey Uchukhlebau Aug 8 '16 at 12:47
  • @Emke can you get your access logs from the server and copy the contents from when you access the pages? – Paul Aug 8 '16 at 12:48
  • It's not a solution, as it doesn't yet solve my problem :) – Emke Aug 8 '16 at 12:48
  • @Paul here's a filtered subset of access logs pastebin.com/SLeKcdnV – Emke Aug 8 '16 at 12:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.