views:

28

answers:

2

Hi all, I want to get the cookie information stored using setcookie function in the source code of the php.. not the php source code.. What is the corresponding C code for _COOKIE['xx'];

In other words where is the _COOKIE array created and populated?

A: 

Cookie info comes as part of your http headers (that the browser sends). PHP makes it easier to access them by parsing it out in to a neat array and putting it in _COOKIE. You'll have to do it in C.

MovieYoda
+1  A: 

The $_COOKIE variable doesn't use JIT (just-in-time initialization), so it's always accessible by reading the global variables table EG(symbol_table):

zval **cookie_var;
if (zend_hash_find(&EG(symbol_table), "_COOKIE", sizeof("_COOKIE"),
        (void**)&cookie_var) == SUCCESS) {
    /* do something with cookie_var */
} else {
    /* handle error; shouldn't happen */
}
Artefacto
Where would I pass the name 'views'??is the value of **(cookie_var) = 'views'?
Karthick
Artefacto
ok.. now the zval char mismatch error occurs.. I am new to this extension writing. So can u help me? I know that the variable name is 'views' and it is going to be constant.. So I dont have to get that from the user..
Karthick
@Kar I recommend you start by reading some of the resources [here](http://stackoverflow.com/questions/2970682/how-to-develop-c-extentions-for-php-apps/2970709#2970709).
Artefacto
Yes.. I ll do that.. bUt I need it kind of very urgent. I just want to read 'views' variable set by the user in the extension. Can u give me the working snippet for that?
Karthick
I don want the extension code.. as i am just adding an api.. So would be great if u could help me with the snippet..
Karthick
It works for me now.. Thanks
Karthick