Take the 2-minute tour ×

I have declared a structure that look like

 typedef struct
     char* key;
     char* value;

and in the session structure, i declared a variable as

 struct session

    char* id;
    .....  // other session variables
    kvPair* pair;

Now in the session_start I have initialised the values for the pair variable and I have to access these values in /ext/mysql extension. A suggestion on how to achieve it would be greatly appreciated

share|improve this question
OK, what are you trying to do? And what has the mysql extension to do with this? –  Artefacto Sep 1 '10 at 1:38
@Artefacto: Well since hes posted C code im going to guess hes customizing the mysql extension... Sill more explanation would be nice... as well as a tag for the actual language hes working with (i only guessed at C) –  prodigitalson Sep 1 '10 at 1:42
I am trying to control the access to the database based on the user information. Thats a part of my research on securing the server-side-database access. I tried to include the /ext/php_session.h in /ext/mysql.c . Is this the right way to do? or is there a better way of doing things? –  Karthick Sep 1 '10 at 1:45
omg, who adviced you to do in this way? –  zerkms Sep 1 '10 at 2:06
@zerkms. Are u talking about the scheme or the inclusion of session.h file in /ext/mysql.c? –  Karthick Sep 1 '10 at 2:16
show 1 more comment

1 Answer

up vote 0 down vote accepted

I'm not sure what you're trying to do, but if you want to read data that was saved in the session e.g. through this script:

$_SESSION["key"] = "data";

Then yes, you can use the API exposed by the session extension:

#include "ext/session/php_session.h"

Then you have these functions:

void php_session_start(TSRMLS_D); /* analogue to session_start() in userspace */
int php_get_session_var(char *name, size_t namelen, zval ***state_var TSRMLS_DC);
share|improve this answer
once I use that. I am able to directly access the session structure variables. For example. to access id variable, i just did PS(id) and it worked like charms. Thank you for your suggestions though! –  Karthick Sep 1 '10 at 2:13
@Karth Just because you can, doesn't mean you should. The session extension provides an API, use it. If you violate the abstractions, your code will stop working when the internal structures you're accessing change in some future version. –  Artefacto Sep 1 '10 at 2:26
@Karth Well, in the particular case of fetching the current id, doesn't seem to exist any API. –  Artefacto Sep 1 '10 at 2:27
add comment

Your Answer


