0

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?

hakre
  • 193,403
  • 52
  • 435
  • 836
Karthick
  • 2,844
  • 4
  • 34
  • 55

2 Answers2

1

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
  • 96,375
  • 17
  • 202
  • 225
  • Where would I pass the name 'views'?? is the value of **(cookie_var) = 'views'? – Karthick Aug 31 '10 at 04:18
  • @Kar You'd have to do another hash lookup on the array `cookie_var`: `zend_hash_find(Z_ARRVAL_PP(cookie_var), "views", sizeof("views"), (void**)&my_var)` – Artefacto Aug 31 '10 at 04:24
  • 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 Aug 31 '10 at 04:29
  • @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 Aug 31 '10 at 04:43
  • 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 Aug 31 '10 at 04:46
  • 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 Aug 31 '10 at 05:01
0

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.

Srikar Appalaraju
  • 71,928
  • 54
  • 216
  • 264