rryqszq4 / ngx-php

ngx-php - Embedded php7 or php8 scripting language for nginx module. Mainline development version of the ngx-php.
BSD 2-Clause "Simplified" License
586 stars 56 forks source link

How ı can change variable #34

Open fatalafitili opened 5 years ago

fatalafitili commented 5 years ago

`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 commented 5 years ago

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

fatalafitili commented 5 years ago

@rryqszq4 I wait u

rryqszq4 commented 5 years ago

@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 commented 5 years ago

@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 commented 5 years ago

@fatalafitili For example about what transactions?

fatalafitili commented 5 years ago

@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 commented 5 years ago

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

fatalafitili commented 5 years ago

@rryqszq4

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

rryqszq4 commented 5 years ago

@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 commented 5 years ago

@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 commented 5 years ago

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 commented 5 years ago

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

image