Jump to content

PHP extension access internal variables


castis

Recommended Posts

I have an extension that gives you filterGet(), it's being called via filterGet($_GET, [arg, ...]); and i'd like to eliminate the first argument and grab $_GET straight from the engine.

 

How would I go about doing that?

 

Thanks!

Link to comment
Share on other sites

I'm doing this in c

 

the code I currently am fiddling with is

 

ZEND_FUNCTION(autopage){
    long threadCount = 0;
int perPage = 0;
int currentPage = 0;

/* get and assign arguments */
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lii", &threadCount, &perPage, &currentPage) == FAILURE){
        RETURN_STRING("Bad parameters!", true);
    }
    long totalPagesDecimal = threadCount/perPage;
double totalPages = ceil(totalPagesDecimal);

RETURN_DOUBLE(totalPages);
}

 

i want to know how to get $_GET directly from the engine while inside an extension. :)

Link to comment
Share on other sites

btherl, you're the man.

 

the code that works is as follows

 

if you have ?apples=oranges at the end of your page, this will filterGet() will return 'oranges'

 

ZEND_FUNCTION(filterGet)
{
zval **data;
HashTable *arr_hash;
HashPosition pointer;
int array_count;

zval *arr = PG(http_globals)[TRACK_VARS_GET];

    arr_hash = Z_ARRVAL_P(arr);
    array_count = zend_hash_num_elements(arr_hash);

for(
	zend_hash_internal_pointer_reset_ex(arr_hash, &pointer); 
	zend_hash_get_current_data_ex(arr_hash, (void**) &data, &pointer) == SUCCESS; 
	zend_hash_move_forward_ex(arr_hash, &pointer)) {

	if (Z_TYPE_PP(data) == IS_STRING) {
		PHPWRITE(Z_STRVAL_PP(data), Z_STRLEN_PP(data));
	}

	return;
    } 

RETURN_NULL();
return;
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.