access to variables

php.internals

Ci

19 years ago
Hello, I'm writing small patch to php mail function. I want to write in log file connection between sent message and place where mail function was executed. My idea is to determine the person who sent message. Is there any way to get this information? Regards, Ci

Ci

19 years ago
I tried to use smth like that: zval *data = NULL; zend_hash_find(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER]), "DOCUMENT ROOT", sizeof("DOCUMENT ROOT"), &data); strcpy(buffer, Z_STRVAL_P(data); Then I write the buffer to file, but I don't get correct variable. I'm working with php-5.2.1. Am I in a good way to solve my problem? Regards, Ci

Tijnema !

19 years ago
On 4/24/07, Ci <ciptok@gmail.com> wrote:
> I tried to use smth like that: > > zval *data = NULL; > > zend_hash_find(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER]), > "DOCUMENT ROOT", sizeof("DOCUMENT ROOT"), &data); > strcpy(buffer, Z_STRVAL_P(data); > > Then I write the buffer to file, but I don't get correct variable. > I'm working with php-5.2.1. > > Am I in a good way to solve my problem? > > Regards, > Ci
Ok, i don't know a lot about the core of PHP, but i do know the C language. First of all, i don't see you declaring buffer somewhere, i guess you did it without showing, or that it is in the core. But if it isn't both, you should do :) Also note that buffer should be declared as char *buffer to be able to use the strcpy function on it. Second, when you're using the strcpy function, you have 2 '(' used, and only one ')' I guess this is a type here. (else it would return error on compilation i guess) Third, the function strcpy also has a return value. It should be returned to a pointer to the string where it is copied to. so it would become: buffer = strcpy(buffer,Z_STRVAL_P(data)); If all above noted is correct, then it is a problem with your zend_hash_find function, but as i noted already, i don't know a lot of the PHP core, so i can't help further with it. Tijnema

Ci

19 years ago
Tijnema ! napisał(a):
> Ok, i don't know a lot about the core of PHP, but i do know the C language. > > First of all, i don't see you declaring buffer somewhere, i guess you > did it without showing, or that it is in the core. But if it isn't > both, you should do :) > Also note that buffer should be declared as char *buffer to be able to > use the strcpy function on it.
I declared it before, I just wrote here my idea to solve the problem.
> > Second, when you're using the strcpy function, you have 2 '(' used, > and only one ')' > I guess this is a type here. (else it would return error on compilation > i guess)
I rewrote all this stuff from my second computer where I'm working on it. There's second ')' of course. It was just my mistake.
> Third, the function strcpy also has a return value. It should be > returned to a pointer to the string where it is copied to. > so it would become: > buffer = strcpy(buffer,Z_STRVAL_P(data));
strcpy function returns pointer to destination data so this can't be the problem. buffer should have correct data.
> If all above noted is correct, then it is a problem with your > zend_hash_find function, but as i noted already, i don't know a lot of > the PHP core, so i can't help further with it.
I don't know a lot of PHP core too and propably there's smth wrong with this code. Thanks for respond.

Stefan Esser

19 years ago
Hello,
> zend_hash_find(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER]), > "DOCUMENT ROOT", sizeof("DOCUMENT ROOT"), &data); > strcpy(buffer, Z_STRVAL_P(data);
It is called DOCUMENT_ROOT, not DOCUMENT ROOT... -sesser

Ci

19 years ago
Stefan Esser napisał(a):
> Hello, > >> zend_hash_find(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER]), >> "DOCUMENT ROOT", sizeof("DOCUMENT ROOT"), &data); >> strcpy(buffer, Z_STRVAL_P(data); > It is called DOCUMENT_ROOT, not DOCUMENT ROOT...
It was mistake in rewriting. If I choose any php variable, such as DOCUMENT_ROOT, SERVER_NAME I got data in buffer like: '`5u', '1x'. Is that method of getting variable correct?

Stefan Esser

19 years ago
Ci schrieb:
> Stefan Esser napisał(a): >> Hello, >> >>> zend_hash_find(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER]), >>> "DOCUMENT ROOT", sizeof("DOCUMENT ROOT"), &data); >>> strcpy(buffer, Z_STRVAL_P(data); >> It is called DOCUMENT_ROOT, not DOCUMENT ROOT... > It was mistake in rewriting. If I choose any php variable, such as > DOCUMENT_ROOT, SERVER_NAME I got data in buffer like: '`5u', '1x'. > Is that method of getting variable correct? >
No. The correct way for getting the variable is zval **data; ... if (zend_hash_find(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER]), "DOCUMENT_ROOT", sizeof("DOCUMENT_ROOT"), &data)==SUCCESS) { ... strlcpy(buffer, Z_STRVAL_PP(data), sizeof(buffer)); } -sesser

Ci

19 years ago
Stefan Esser napisał(a):
> No. The correct way for getting the variable is > > > zval **data; > ... > if (zend_hash_find(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER]), > "DOCUMENT_ROOT", sizeof("DOCUMENT_ROOT"), &data)==SUCCESS) { > ... > strlcpy(buffer, Z_STRVAL_PP(data), sizeof(buffer)); > }
I tried to use it. I figured out that zend_hash_find function returns SUCCESS, but when the strlcpy is executed I can't do anything after that. I'm thinking about writing results to file. I used: FILE *log; log = fopen("/var/log/mail_spam", "w"); fprintf(log, "data: %s", buffer); It writes any data I want but only when I don't execute strlcpy (or strcpy) function. What could be the problem?

Tijnema !

19 years ago
On 4/24/07, Ci <ciptok@gmail.com> wrote: > Stefan Esser napisał(a): > > No. The correct way for getting the variable is > > > > > > zval **data; > > ... > > if (zend_hash_find(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER]), > > "DOCUMENT_ROOT", sizeof("DOCUMENT_ROOT"), &data)==SUCCESS) { > > ... > > strlcpy(buffer, Z_STRVAL_PP(data), sizeof(buffer)); > > } > I tried to use it. I figured out that zend_hash_find function returns > SUCCESS, but when the strlcpy is executed I can't do anything after > that. I'm thinking about writing results to file. > I used: > > FILE *log; > log = fopen("/var/log/mail_spam", "w"); > > fprintf(log, "data: %s", buffer); > > It writes any data I want but only when I don't execute strlcpy (or > strcpy) function. What could be the problem? I believe that the source string needs to be 0 terminated (\0). Don't ask me how to fix it ;) Tijnema

Ci

19 years ago
Tijnema ! napisał(a):
> I believe that the source string needs to be 0 terminated (\0). > Don't ask me how to fix it ;)
Thanks all of You. I solve all problems. Hmmm, maybe there are some things to make better, but the main idea is solved. BTW. Documentation of php API is tragic ;) Regards, Ci

Tijnema !

19 years ago
On 4/24/07, Ci <ciptok@gmail.com> wrote: > Tijnema ! napisał(a): > > I believe that the source string needs to be 0 terminated (\0). > > Don't ask me how to fix it ;) > Thanks all of You. I solve all problems. Hmmm, maybe there are some > things to make better, but the main idea is solved. > > BTW. Documentation of php API is tragic ;) > > Regards, > Ci Well, if you have some spare time, rewrite it ;) Tijnema

Antony Dovgal

19 years ago
On 04/25/2007 01:02 AM, Ci wrote:
> Tijnema ! napisał(a): > > I believe that the source string needs to be 0 terminated (\0). >> Don't ask me how to fix it ;) > Thanks all of You. I solve all problems. Hmmm, maybe there are some > things to make better, but the main idea is solved. > > BTW. Documentation of php API is tragic ;)
Do you want to help with the docs? That would be very much appreciated.
-- Wbr, Antony Dovgal

Ci

19 years ago
Antony Dovgal napisał(a):
> Do you want to help with the docs? > That would be very much appreciated.
I can help, but I don't think I'll be able to write a new documentation. You saw that my knowledge in php API wasn't too high ;P

Richard Lynch

19 years ago
On Tue, April 24, 2007 4:02 pm, Ci wrote:
> Tijnema ! napisa³(a): > > I believe that the source string needs to be 0 terminated (\0). >> Don't ask me how to fix it ;) > Thanks all of You. I solve all problems. Hmmm, maybe there are some > things to make better, but the main idea is solved. > > BTW. Documentation of php API is tragic ;)
There's some good stuff up on http://php.net in the Zend Internals bit. And Sara Goleman's articles on Zend.com, and her dead-trees book. It can't be THAT awful if I managed to stumble through it to write a simple extension... Do feel free to submit better docs, of course. :-)
-- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So?

Marcus Börger

19 years ago
Hello Ci, Tuesday, April 24, 2007, 11:02:52 PM, you wrote:
> Tijnema ! napisał(a): > > I believe that the source string needs to be 0 terminated (\0). >> Don't ask me how to fix it ;) > Thanks all of You. I solve all problems. Hmmm, maybe there are some > things to make better, but the main idea is solved.
> BTW. Documentation of php API is tragic ;)
Have a look here: http://talks.somabo.de/200611_php_code_camp.pdf Best regards, Marcus

Ci

19 years ago
Marcus Boerger napisał(a):
> Have a look here: http://talks.somabo.de/200611_php_code_camp.pdf
Ohh this is really good. It should be in more reach place. Regards, Ci

DvDmanDT

19 years ago
Doesn't the zval contain info about the length of the string?
-- // DvDmanDT mail: dvdmandt¤telia.com msn: dvdmandt¤hotmail.com "Ci" <ciptok@gmail.com> skrev i meddelandet news:75.B1.60955.4F31E264@pb1.pair.com...