Hello,
We are having some trouble with using $_Get variables in Drupal with anonymous users. We have several pages using PHP input that take a variable from the query string.
For example:
echo $_GET['myvar'];
For anonymous users, the GET variables sent in the query string are ignored, so the above code would not print anything. The strange thing is that this works fine for an authenticated user, i.e. if you are logged in the above code will print the value of myvar= sent in the query string.
Any ideas as to why this is happening and how to allow GET variables to work for anonymous users?
Thanks in advance,
On 08/25/2010 11:34 AM, Mark Canney wrote:
For anonymous users, the GET variables sent in the query string are ignored, ... The strange thing is that this works fine for an authenticated user, ...
Hi Mark,
Are you sure the problem is specifically with $_GET vars? Hearing only what you've explained, it seems to me a more likely cause is Drupal's page caching mechanism, which will save pages as static (or near-static) chunks of HTML and then display those chunks until the cache is x minutes old. Such caching doesn't apply to authenticated users, though, so authenticated users get each page generated completely new on each request. Anonymous users, though, would get the cached version, which would be a few minutes old, at least.
You might want to try again with caching turned off. In D6, you can do this at admin/settings/performance in the "Page cache" section at the top of the page.
Let us know if that fixes the problem or not.
Of course, it may just bring to light a new problem, which is: you probably don't want to run with cache turned off completely, so how can you do both at the same time? I don't think you can: if you want up-to-the-second dynamic data, you can't cache the stuff.
But you may be able to get away with block-level caching or similarly caching only the parts of the page where your dynamic data does not appear.
All the best, Allen
This does seem to be a Drupal caching issue; if we press "Flush All Cache" and then connect anonymously, the page "GET" works correctly one time - but then gets "stuck" on that page.
We're not live yet, but this is an example of a dropdown which works for authenticated users but not anonymous users:
http://library2.lehigh.edu/content/new_books_asa
We've turned off all caching in Performance (we're version 6) but there still seems to be some Drupal caching occurring because this is not working.
Thank you for your generosity!
Mark
Allen Shaw wrote:
On 08/25/2010 11:34 AM, Mark Canney wrote:
For anonymous users, the GET variables sent in the query string are ignored, ... The strange thing is that this works fine for an authenticated user, ...
Hi Mark,
Are you sure the problem is specifically with $_GET vars? Hearing only what you've explained, it seems to me a more likely cause is Drupal's page caching mechanism, which will save pages as static (or near-static) chunks of HTML and then display those chunks until the cache is x minutes old. Such caching doesn't apply to authenticated users, though, so authenticated users get each page generated completely new on each request. Anonymous users, though, would get the cached version, which would be a few minutes old, at least.
You might want to try again with caching turned off. In D6, you can do this at admin/settings/performance in the "Page cache" section at the top of the page.
Let us know if that fixes the problem or not.
Of course, it may just bring to light a new problem, which is: you probably don't want to run with cache turned off completely, so how can you do both at the same time? I don't think you can: if you want up-to-the-second dynamic data, you can't cache the stuff.
But you may be able to get away with block-level caching or similarly caching only the parts of the page where your dynamic data does not appear.
All the best, Allen
On 08/25/2010 02:03 PM, Mark Canney wrote:
This does seem to be a Drupal caching issue; if we press "Flush All Cache" and then connect anonymously, the page "GET" works correctly one time - but then gets "stuck" on that page.
Okay, so it's not as simple as we thought. :-) Well, this problem is not ringing any bells with me - I mean, I don't recognize it as a common symptom of a problem I know about.
If you want to post some code, I or someone else might be able to spot the issue.
- Allen
OK, here's a test page with a simple form (which is intended to print out what is placed in the form - code is included on page):
http://library2.lehigh.edu/content/test
You will see the form "works" the first time but subsequent attempts do not "refresh".
NB: All caching is disabled! We are at version 6.
Thanks,
Mark
Allen Shaw wrote:
On 08/25/2010 02:03 PM, Mark Canney wrote:
This does seem to be a Drupal caching issue; if we press "Flush All Cache" and then connect anonymously, the page "GET" works correctly one time - but then gets "stuck" on that page.
Okay, so it's not as simple as we thought. :-) Well, this problem is not ringing any bells with me - I mean, I don't recognize it as a common symptom of a problem I know about.
If you want to post some code, I or someone else might be able to spot the issue.
- Allen
What is it that you are trying to do? Why not build a proper module and use the Form API instead of embedding PHP in a node? (I'm not sure how filter caching will handle that)
-Mike __________________ Michael Prasuhn http://mikeyp.net
On Aug 25, 2010, at 1:18 PM, Mark Canney wrote:
OK, here's a test page with a simple form (which is intended to print out what is placed in the form - code is included on page):
http://library2.lehigh.edu/content/test
You will see the form "works" the first time but subsequent attempts do not "refresh".
NB: All caching is disabled! We are at version 6.
Thanks,
Mark
Allen Shaw wrote:
On 08/25/2010 02:03 PM, Mark Canney wrote:
This does seem to be a Drupal caching issue; if we press "Flush All Cache" and then connect anonymously, the page "GET" works correctly one time - but then gets "stuck" on that page.
Okay, so it's not as simple as we thought. :-) Well, this problem is not ringing any bells with me - I mean, I don't recognize it as a common symptom of a problem I know about.
If you want to post some code, I or someone else might be able to spot the issue.
- Allen
-- Mark Canney Senior Systems Specialist Library & Technology Services Lehigh University 610-758-1432 mark.canney@lehigh.edu
-- [ Drupal support list | http://lists.drupal.org/ ]
On 08/25/2010 05:10 PM, Michael Prasuhn wrote:
What is it that you are trying to do? Why not build a proper module and use the Form API instead of embedding PHP in a node? (I'm not sure how filter caching will handle that)
Mark, Michael has a point here. I had assumed you were working with code in a module. Probably that's a better way to go.
- Allen
On Aug 25, 2010, at 9:34 AM, Mark Canney wrote:
Any ideas as to why this is happening and how to allow GET variables to work for anonymous users?
Caching.
Turn it off on the Performance page under site configuration.
-Mike __________________ Michael Prasuhn http://mikeyp.net
Thanks to everyone for your feedback. We literally stumbled across a resolution: At the same time, we noticed a problem with images in the node mysteriously resizing to a 180 width. From there we found a thread which suggested this problem had been fixed by giving "permission to "enable mobile plugin for" for both anonymous and authenticated users". We had just installed the mobile plugin module (before the problem started) and neglected to give permissions to anonymous users.
When we executed the fix for the mysteriously resizing images, the problem with the ignored variables for anonymous users was corrected as well.
As a Drupal newbie, I'm not sure what the lesson is here but I will duck as you should feel free to chime.
Mark
Mark Canney wrote:
Hello,
We are having some trouble with using $_Get variables in Drupal with anonymous users. We have several pages using PHP input that take a variable from the query string.
For example:
echo $_GET['myvar'];
For anonymous users, the GET variables sent in the query string are ignored, so the above code would not print anything. The strange thing is that this works fine for an authenticated user, i.e. if you are logged in the above code will print the value of myvar= sent in the query string.
Any ideas as to why this is happening and how to allow GET variables to work for anonymous users?
Thanks in advance,