Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 490709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T01:56:13+00:00 2026-05-13T01:56:13+00:00

I have written a PHP extension library in C++. I am writing the extension

  • 0

I have written a PHP extension library in C++. I am writing the extension for PHP 5.x ad above.

I need to access PHP superglobals in my C++ code. Does anyone know how to do this?. A code snippet or pointer (no pun inteded) to a similar resource (no pun …) would be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T01:56:13+00:00Added an answer on May 13, 2026 at 1:56 am

    What data do you actually need? – Best way for most data is to refer to the C structure they are coming from. For instance with request data you can check the sapi_globals, accessible using the SG() macro, session data is available via the session module, …

    If you really need access to a super global you can find it in the EG(symbol_table) hash table. As PHP has a JIT mechanism to provide super globals only when needed you might need to call zend_auto_global_disable_jit() first to disable this.


    Answering the comment below: Is any of this data enough:

    typedef struct {
        const char *request_method;
        char *query_string;
        char *post_data, *raw_post_data;
        char *cookie_data;
        long content_length;
        uint post_data_length, raw_post_data_length;
    
        char *path_translated;
        char *request_uri;
    
        const char *content_type;
    
        zend_bool headers_only;
        zend_bool no_headers;
        zend_bool headers_read;
    
        sapi_post_entry *post_entry;
    
        char *content_type_dup;
    
        /* for HTTP authentication */
        char *auth_user;
        char *auth_password;
        char *auth_digest;
    
        /* this is necessary for the CGI SAPI module */
        char *argv0;
    
        /* this is necessary for Safe Mode */
        char *current_user;
        int current_user_length;
    
        /* this is necessary for CLI module */
        int argc;
        char **argv;
        int proto_num;
    } sapi_request_info;
    
    typedef struct _sapi_globals_struct {
        void *server_context;
        sapi_request_info request_info;
        sapi_headers_struct sapi_headers;
        int read_post_bytes;
        unsigned char headers_sent;
        struct stat global_stat;
        char *default_mimetype;
        char *default_charset;
        HashTable *rfc1867_uploaded_files;
            long post_max_size;
            int options;
            zend_bool sapi_started;
            time_t global_request_time;
            HashTable known_post_content_types;
    } sapi_globals_struct;
    

    Then use SG(request_info).request_urior similar, while you should only read these values, not write, so make a copy if needed.

    None of these is enough? – Then go back to what I said above:

    /* untested code, might need some error checking and stuff */
    zval **server_pp;
    zval **value_pp;
    zend_auto_global_disable_jit("_SERVER", sizeof("_SERVER")-1 TSRMLS_CC);
    if (zend_hash_find(EG(symbol_table), "_SERVER", sizeof("_SERVER"), (void**)&server_pp) == FAILURE) {
        zend_bailout(); /* worst way to handle errors */
    }
    if (Z_TYPE_PP(server_pp) != IS_ARRAY) {
        zend_bailout();
    }
    if (zend_hash_find(Z_ARRVAL_PP(server_pp), "YOUR_VARNAME", sizeof("YOUR_VARNAME"), (void**)&value_pp) == FAILURE) {
        zend_bailout();
    }
    /* now do something with value_pp */
    

    Please mind that I jsut typed it here out of my ind without checking anything so it can be wrong, contain typos etc.
    And as a note: You should be aware of the fact that you have to use sizeof() not sizeof()-1 with hash APIs as the terminating null-byte is part of the calculated hash and has functions return SUCCESS or FAILURE, while SUCCESS is defined as 0 and FAILURE as -1 which is not what one might expect, so always use these constants!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 252k
  • Answers 252k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Like others said, Xdebug is your best bet. I'll just… May 13, 2026 at 9:41 am
  • Editorial Team
    Editorial Team added an answer What do you mean by "mipmap changes". The mipmap level… May 13, 2026 at 9:41 am
  • Editorial Team
    Editorial Team added an answer I found similar problems (with difference gem) all over the… May 13, 2026 at 9:41 am

Related Questions

I am thinking of writing a PHP extension library that will use the memcached
Update: I have now written a PHP extension called php_ssdeep for the ssdeep C
I have written a .NET web Service that is to be consumed by a
Most of my application is written in PHP ((Front and Back ends). There is

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.