GWAN:如何读取Cookie [英] GWAN : How to read cookies

查看:109
本文介绍了GWAN:如何读取Cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试读取cookie,但是下面的脚本返回一个空字符串.

http_t *http =  (http_t*)get_env(argv, HTTP_HEADERS);
xbuf_t *read_buf  = (xbuf_t*)get_env(argv, READ_XBUF);
char *p = read_buf->ptr;
char *cookies = http->h_cookies ? p + http->h_cookies : 0;
xbuf_xcat(reply, "<HR>COOKIES [%s]<br>", cookies);

我之前使用以下网址设置了Cookie:http_header(可以在chrome的控制台中看到)

那我该如何阅读cookie?

谢谢您的回答.

我正在使用GWAN 4.11.20

尽管添加了新值,但

解决方案

v4.11仍未同步gwan/includes头而发布.

结果,get_env()在G-WAN脚本中使用的某些值与G-WAN使用的值不匹配.

一种解决方案是更正gwan.h标头中的这些值.访问Cookie的另一种简单方法是使用 READ_XBUF 到达读取缓冲区(请参见连接处理程序"标签)然后使用类似于G-WAN cookies.c 示例的代码查找cookie.

Paulo,一个存在相同问题的G-WAN用户,向我们发送了以下源代码:

int getSessionID(int argc, char *argv[]) {
    http_t *http = (http_t*)get_env(argv, HTTP_HEADERS);
    xbuf_t *read_buf = (xbuf_t*)get_env(argv, READ_XBUF);
    char *p = read_buf->ptr;
    int sessionID = 0;
    if (http) {
        sessionID = http->session_id;
fprintf(stderr, "Get SessionID %d\n", sessionID);        
    }

fprintf(stderr, "Get SessionID Cookie %d\n", http->h_cookies); 

    if (p && *p && http->h_cookies) {
        char *cookies = p + http->h_cookies;
fprintf(stderr, "Get SessionID Cookie %s\n", cookies);
        // The sessionID is on the Cookie
        sessionID = atoi(cookies + 5);
    }
    if (!sessionID) {
        // The sessionID is not on the Cookie so send the server Session_ID   
        sessionID = (int)get_env(argv, SESSION_ID);
    }
    if (!sessionID) {
        // Oops! I have no session from the Server. use the IP Address and a timestamp
        sessionID = (int)get_env(argv, REMOTE_BIN_ADDR) + getms();
    }
    return sessionID;
}

这将使您入门.

I'm trying to read cookies but the script below returns an empty string.

http_t *http =  (http_t*)get_env(argv, HTTP_HEADERS);
xbuf_t *read_buf  = (xbuf_t*)get_env(argv, READ_XBUF);
char *p = read_buf->ptr;
char *cookies = http->h_cookies ? p + http->h_cookies : 0;
xbuf_xcat(reply, "<HR>COOKIES [%s]<br>", cookies);

I have set a cookie previously using : http_header (which I can see in chrome's console)

So how can I read cookies?

Thank you for your answer.

I'm using GWAN 4.11.20

解决方案

v4.11 was issued without synchronizing the gwan/includes headers despite new values being added.

As a result, some of the values used by get_env() in G-WAN scripts do not match the values used by G-WAN.

A solution would be to correct these values in the gwan.h header. Another simpler way to access cookies is to reach the read buffer using READ_XBUF (see the "connection handler" tab) and then look for the cookies using code similar to the G-WAN cookies.c example.

Paulo, a G-WAN user having the same problem has sent us the following source code:

int getSessionID(int argc, char *argv[]) {
    http_t *http = (http_t*)get_env(argv, HTTP_HEADERS);
    xbuf_t *read_buf = (xbuf_t*)get_env(argv, READ_XBUF);
    char *p = read_buf->ptr;
    int sessionID = 0;
    if (http) {
        sessionID = http->session_id;
fprintf(stderr, "Get SessionID %d\n", sessionID);        
    }

fprintf(stderr, "Get SessionID Cookie %d\n", http->h_cookies); 

    if (p && *p && http->h_cookies) {
        char *cookies = p + http->h_cookies;
fprintf(stderr, "Get SessionID Cookie %s\n", cookies);
        // The sessionID is on the Cookie
        sessionID = atoi(cookies + 5);
    }
    if (!sessionID) {
        // The sessionID is not on the Cookie so send the server Session_ID   
        sessionID = (int)get_env(argv, SESSION_ID);
    }
    if (!sessionID) {
        // Oops! I have no session from the Server. use the IP Address and a timestamp
        sessionID = (int)get_env(argv, REMOTE_BIN_ADDR) + getms();
    }
    return sessionID;
}

This will get your started.

这篇关于GWAN:如何读取Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆