Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How ı can change variable #34

Open
fatalafitili opened this issue Mar 7, 2019 · 12 comments
Open

How ı can change variable #34

fatalafitili opened this issue Mar 7, 2019 · 12 comments

Comments

@fatalafitili
Copy link

`user www www;
worker_processes 4;

events {
worker_connections 1024;
}

http {
include mime.types;
default_type application/octet-stream;

keepalive_timeout  65;

client_max_body_size 64k;   
client_body_buffer_size 64k;
php_ini_path /etc/php.ini;

server {
    listen       80;
    server_name  localhost;
    default_type 'application/json; charset=UTF-8';
    
    set $sel 0;
           
    location = / {
		access_by_php '
			$x = 1; 
			ngx_var::set("sel", $x);
		'; 
		return 200 $sel;
    }

}

}`

return 200 $sel; 0 gives

How ı can do ? Can u help me ?

@rryqszq4
Copy link
Owner

rryqszq4 commented Mar 8, 2019

@fatalafitili
I tested that the access_by_php directive was not executed.Need to research in depth.

@fatalafitili
Copy link
Author

fatalafitili commented Mar 8, 2019

@rryqszq4 I wait u

@rryqszq4
Copy link
Owner

rryqszq4 commented Mar 8, 2019

@fatalafitili
The 'return' directive is in the 'rewrite' phase, earlier than the 'access' phase.

Try the following example:

...

set $sel 0;
location = / {
    access_by_php '
        $x = 1; 
        ngx_var::set("sel", $x);
    '; 
    content_by_php '
        echo ngx_var::get("sel");
    ';
}

...

@fatalafitili
Copy link
Author

fatalafitili commented Mar 8, 2019

@fatalafitili
The 'return' directive is in the 'rewrite' phase, earlier than the 'access' phase.

Try the following example:

...

set $sel 0;
location = / {
    access_by_php '
        $x = 1; 
        ngx_var::set("sel", $x);
    '; 
    content_by_php '
        echo ngx_var::get("sel");
    ';
}

...

I know it works but I want to change a variable in nginx.

for example

`set $sel 0;
location = / {
    access_by_php '
        $x = 1; 
        ngx_var::set("sel", $x);
    '; 
    content_by_php '
        echo ngx_var::get("sel");
    ';
    if ($sel = 1) {
     #I want to make transactions here
    }

}`

@rryqszq4 Isn't it possible ?

@rryqszq4
Copy link
Owner

rryqszq4 commented Mar 8, 2019

@fatalafitili
For example about what transactions?

@fatalafitili
Copy link
Author

@rryqszq4
My only goal is to change the value of a nginx variable with php,
I can use that variable in all fields, usually if parameter

@rryqszq4
Copy link
Owner

rryqszq4 commented Mar 8, 2019

@fatalafitili
I think the ‘rewrite_by_php’ directive should be used, but there are some bugs.
=.=

@fatalafitili
Copy link
Author

@rryqszq4

Okay, buddy, I'm gonna do it for now, but I'm waiting for an update. :)

@rryqszq4
Copy link
Owner

rryqszq4 commented Mar 8, 2019

@fatalafitili

Change access_by_php to rewrite_by_php, I found it is ok.

...

set $sel 0;
location = / {
    rewrite_by_php '
        $x = 1; 
        ngx_var::set("sel", $x);
    '; 
    return 200 $sel;
}

...

@fatalafitili
Copy link
Author

@fatalafitili

Change access_by_php to rewrite_by_php, I found it is ok.

...

set $sel 0;
location = / {
    rewrite_by_php '
        $x = 1; 
        ngx_var::set("sel", $x);
    '; 
    return 200 $sel;
}

...

Oh I so happy, this worked thanks dude, i love u <3 @rryqszq4

@fatalafitili
Copy link
Author

fatalafitili commented Mar 9, 2019

Hello dude i again here :) my problem is not fully solved, look this;

image

it's not complete, but it's logic

i did use this but this is not worked, 404 does not;

i need this:

Example:

(php counts how many times each user enters)

php variable if 100, nginx variable 1 do

if nginx variable 1, go return 404 else go location /

i need to do this, can u help again me ? @rryqszq4

@fatalafitili
Copy link
Author

That's the right logic, but it doesn't work;

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants