because there are no example how should it be. and api(zend php) is so complicated
i put some additional code to php4delphi.pas and to php and it work :)
var
php: TpsvPHP;
gl: psapi_globals_struct;
ts: pointer;
cnt: integer;
postTab: pzval;
getTab: pzval;
cookieTab: pzval;
function initTable(val: pzval): Boolean;
begin
result := true;
if _array_init(val, nil, 0) = FAILURE then
begin
zend_Error(E_ERROR, PChar(get_active_function_name(ts) + ': Unable to initialize array'));
ZVAL_FALSE(val);
result := false;
end;
end;
///addst table to server table
addTab2Tab(val, getTab, 'myGETtab');
addTab2Tab(val, postTab, 'myPOSTtab');
addTab2Tab(val, cookieTab, 'myCOOKIEtab');
///in php must be function which "unpack" GET , POST, COOkie form $_SERVER array
//something like this
/// if(array_key_exists('myGETtab',$_SERVER)) {
/// $_GET=$_SERVER['myGETtab'];
///
///}
///if(array_key_exists('myCOOKIEtab',$_SERVER)) {
/// $_COOKIE=$_SERVER['myCOOKIEtab'];
//
///}
//// }
/////////////
if Assigned(php) then
begin
for cnt := 0 to php.Variables.Count - 1 do
begin
php_register_variable(PChar(php.Variables[cnt].Name),
PChar(php.Variables[cnt].Value), val, p);
end;
end;
end;
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello
I want to share my solution.
because there are no example how should it be. and api(zend php) is so complicated
i put some additional code to php4delphi.pas and to php and it work :)
procedure php_delphi_register_variables(val: pzval; p: pointer); cdecl;
var
php: TpsvPHP;
gl: psapi_globals_struct;
ts: pointer;
cnt: integer;
postTab: pzval;
getTab: pzval;
cookieTab: pzval;
function initTable(val: pzval): Boolean;
begin
result := true;
if _array_init(val, nil, 0) = FAILURE then
begin
zend_Error(E_ERROR, PChar(get_active_function_name(ts) + ': Unable to initialize array'));
ZVAL_FALSE(val);
result := false;
end;
end;
procedure addTab2Tab(tab1, tab2: pzval; key: string);
begin
//to tab1 adds tab2
add_assoc_zval_ex(tab1, pchar(key), StrLen(pchar(key)) + 1, tab2);
end;
procedure addStr2Tab(key, strVal: string; tab: pzval);
begin
//adds string to assoc table
add_assoc_string_ex(tab, pchar(key), StrLen(pchar(key)) + 1, pchar(strVal), 1);
end;
begin
ts := ts_resource_ex(0, nil);
gl := GetSAPIGlobals(ts);
php := TpsvPHP(gl^.server_context);
php_register_variable('PHP_SELF', '_', nil, p);
php_register_variable('SERVER_NAME', 'DELPHI', val, p);
php_register_variable('SERVER_SOFTWARE', 'Delphi', val, p);
php_register_variable('IsLibrary', 'False', val, p);
////////////////
if not initTable(val) then exit;
postTab := MAKE_STD_ZVAL();
if not initTable(postTab) then exit;
getTab := MAKE_STD_ZVAL();
if not initTable(getTab) then exit;
cookieTab := MAKE_STD_ZVAL();
if not initTable(cookieTab) then exit;
addStr2Tab('aaa', '111', postTab);
addStr2Tab('bbb', 'k122223ey', postTab);
addStr2Tab('ccc', 'ke333123y', postTab);
addStr2Tab('1s1', 'kfffey', getTab);
addStr2Tab('s23', 'k1ccc23ey', getTab);
addStr2Tab('s12', 'ke1ccc23y', getTab);
addStr2Tab('ala', 'kenjjjy', cookieTab);
addStr2Tab('ola', 'k123jjjey', cookieTab);
addStr2Tab('jola', 'kejj123y', cookieTab);
///addst table to server table
addTab2Tab(val, getTab, 'myGETtab');
addTab2Tab(val, postTab, 'myPOSTtab');
addTab2Tab(val, cookieTab, 'myCOOKIEtab');
///in php must be function which "unpack" GET , POST, COOkie form $_SERVER array
//something like this
/// if(array_key_exists('myGETtab',$_SERVER)) {
/// $_GET=$_SERVER['myGETtab'];
///
///}
///if(array_key_exists('myPOSTtab',$_SERVER)) {
/// $_POST=$_SERVER['myPOSTtab'];
///
///}
///if(array_key_exists('myCOOKIEtab',$_SERVER)) {
/// $_COOKIE=$_SERVER['myCOOKIEtab'];
//
///}
//// }
/////////////
if Assigned(php) then
begin
for cnt := 0 to php.Variables.Count - 1 do
begin
php_register_variable(PChar(php.Variables[cnt].Name),
PChar(php.Variables[cnt].Value), val, p);
end;
end;
end;
i ve made it in php4delphi 6.3.3 (delphi 7) php 5.2 ( offcourse without threads in my own written in delphi www server)
/Zielony