# Module variable get\_handler() runs before filter?

**URL:** <https://www.ruby-forum.com/t/module-variable-get-handler-runs-before-filter/221940>\
**Category:** NGINX\
**Created:** [August 6, 2012, 10:27am UTC](https://www.ruby-forum.com/t/module-variable-get-handler-runs-before-filter/221940 "2012-08-06T10:27:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [August 6, 2012, 10:27am UTC](https://www.ruby-forum.com/t/module-variable-get-handler-runs-before-filter/221940/1 "2012-08-06T10:27:34Z")

</div>

Good day,

I am writing a filter module, that has to set a environment variable to  
a certain value, if a special condition is met.

For example, if there is &flag=true in the arguments, I want the PHP to  
see a $\_SERVER[‘FLAG\_DETECTED’] variable. (I know that you might  
suggest just checking for $\_GET[‘flag’] , but what I describe here is  
oversimplification of an actual case)

The only way I see of doing it is adding “fastcgi\_param FLAG\_DETECTED  
$flag\_var;” and then changing the $flag\_var in module.

On detection of this special value (&flag=true) , my filter (inserted at  
ngx\_http\_top\_header\_filter) creates a context, adds it to the request (  
with ngx\_http\_set\_ctx(r,my\_module)) , but when the variable’s  
get\_handle() runs ngx\_http\_get\_module\_ctx( r, my\_module ), I receive  
NULL instead of the context.

My prints to the log show that the get\_handle() runs prior to filter,  
and the CTX is not set  
Is there any way to do what I want?  
Thank you

Posted at Nginx Forum:

> **[module variable get\_handler() runs before filter?](https://forum.nginx.org/read.php?2,229322,229322#msg-229322)**
>
> Good day, I am writing a filter module, that has to set a environment variable to a certain value, if a special condition is met. For example, if there is &flag=true in the arguments, I want the PHP to see a $\_SERVER\['FLAG\_DETECTED' \] variable....
