PageRenderTime 51ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/PHPAPI.pas

http://php4delphi.googlecode.com/
Pascal | 864 lines | 602 code | 210 blank | 52 comment | 98 complexity | df1070c31ec7dc6ca25b8500b773b760 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception
  1. {*******************************************************}
  2. { PHP4Delphi }
  3. { PHP - Delphi interface }
  4. { }
  5. { Author: }
  6. { Serhiy Perevoznyk }
  7. { serge_perevoznyk@hotmail.com }
  8. { http://users.chello.be/ws36637 }
  9. {*******************************************************}
  10. {$I PHP.INC}
  11. { $Id: PHPAPI.pas,v 6.2 02/2006 delphi32 Exp $ }
  12. unit phpAPI;
  13. interface
  14. uses
  15. Windows, SysUtils, ZendTypes, PHPTypes, zendAPI,
  16. {$IFDEF VERSION6}Variants,{$ENDIF}WinSock;
  17. var
  18. php_request_startup: function(TSRMLS_D : pointer) : Integer; cdecl;
  19. php_request_shutdown: procedure(dummy : Pointer); cdecl;
  20. php_module_startup: function(sf : pointer; additional_modules : pointer; num_additional_modules : uint) : Integer; cdecl;
  21. php_module_shutdown: procedure(TSRMLS_D : pointer); cdecl;
  22. php_module_shutdown_wrapper: function (globals : pointer) : Integer; cdecl;
  23. sapi_startup: procedure (module : pointer); cdecl;
  24. sapi_shutdown: procedure; cdecl;
  25. sapi_activate: procedure (p : pointer); cdecl;
  26. sapi_deactivate: procedure (p : pointer); cdecl;
  27. sapi_add_header_ex: function(header_line : pchar; header_line_len : uint; duplicated : zend_bool; replace : zend_bool; TSRMLS_DC : pointer) : integer; cdecl;
  28. php_execute_script : function (primary_file: pointer; TSRMLS_D : pointer) : Integer; cdecl;
  29. php_handle_aborted_connection: procedure; cdecl;
  30. php_register_variable: procedure(_var : PChar; val: PChar; track_vars_array: pointer; TSRMLS_DC : pointer); cdecl;
  31. // binary-safe version
  32. php_register_variable_safe: procedure(_var : PChar; val : PChar; val_len : integer; track_vars_array : pointer; TSRMLS_DC : pointer); cdecl;
  33. php_register_variable_ex: procedure(_var : PChar; val : pzval; track_vars_array : pointer; TSRMLS_DC : pointer); cdecl;
  34. //php_output.h
  35. php_output_startup: procedure(); cdecl;
  36. php_output_activate: procedure (TSRMLS_D : pointer); cdecl;
  37. php_output_set_status: procedure(status: boolean; TSRMLS_DC : pointer); cdecl;
  38. php_output_register_constants: procedure (TSRMLS_D : pointer); cdecl;
  39. php_start_ob_buffer: function (output_handler : pzval; chunk_size : uint; erase : boolean; TSRMLS_DC : pointer) : integer; cdecl;
  40. php_start_ob_buffer_named: function (const output_handler_name : PChar; chunk_size : uint; erase : boolean; TSRMLS_DC : pointer) : integer; cdecl;
  41. php_end_ob_buffer: procedure (send_buffer : boolean; just_flush : boolean; TSRMLS_DC : pointer); cdecl;
  42. php_end_ob_buffers: procedure (send_buffer : boolean; TSRMLS_DC : pointer); cdecl;
  43. php_ob_get_buffer: function (p : pzval; TSRMLS_DC : pointer) : integer; cdecl;
  44. php_ob_get_length: function (p : pzval; TSRMLS_DC : pointer) : integer; cdecl;
  45. php_start_implicit_flush: procedure (TSRMLS_D : pointer); cdecl;
  46. php_end_implicit_flush: procedure (TSRMLS_D : pointer); cdecl;
  47. php_get_output_start_filename: function (TSRMLS_D : pointer) : pchar; cdecl;
  48. php_get_output_start_lineno: function (TSRMLS_D : pointer) : integer; cdecl;
  49. php_ob_handler_used: function (handler_name : pchar; TSRMLS_DC : pointer) : integer; cdecl;
  50. php_ob_init_conflict: function (handler_new : PChar; handler_set : pChar; TSRMLS_DC : pointer) : integer; cdecl;
  51. function GetSymbolsTable(TSRMLS_DC : pointer) : PHashTable;
  52. function GetTrackHash(Name : string; TSRMLS_DC : pointer) : PHashTable;
  53. function GetSAPIGlobals(TSRMLS_DC : pointer) : Psapi_globals_struct;
  54. procedure phperror(Error : PChar);
  55. var
  56. //php_string.h
  57. php_strtoupper: function (s : PChar; len : size_t) : PChar; cdecl;
  58. php_strtolower: function (s : PChar; len : size_t) : PChar; cdecl;
  59. php_strtr: function (str : PChar; len : Integer; str_from : PChar;
  60. str_to : PChar; trlen : Integer) : PChar; cdecl;
  61. php_stripcslashes: procedure (str : PChar; len : PInteger); cdecl;
  62. php_basename: function (str : PChar; len : size_t; suffix : PChar;
  63. sufflen : size_t) : PChar; cdecl;
  64. php_dirname: procedure (str : PChar; len : Integer); cdecl;
  65. php_stristr: function (s : PByte; t : PByte; s_len : size_t; t_len : size_t) : PChar; cdecl;
  66. php_str_to_str: function (haystack : PChar; length : Integer; needle : PChar;
  67. needle_len : Integer; str : PChar; str_len : Integer;
  68. _new_length : PInteger) : PChar; cdecl;
  69. php_strip_tags: procedure (rbuf : PChar; len : Integer; state : PInteger;
  70. allow : PChar; allow_len : Integer); cdecl;
  71. php_implode: procedure (var delim : zval; var arr : zval;
  72. var return_value : zval); cdecl;
  73. php_explode: procedure (var delim : zval; var str : zval;
  74. var return_value : zval; limit : Integer); cdecl;
  75. var
  76. php_info_html_esc: function (str : PChar; TSRMLS_DC : pointer) : PChar; cdecl;
  77. php_print_info_htmlhead: procedure (TSRMLS_D : pointer); cdecl;
  78. php_print_info: procedure (flag : Integer; TSRMLS_DC : pointer); cdecl;
  79. php_info_print_table_colspan_header: procedure (num_cols : Integer;
  80. header : PChar); cdecl;
  81. php_info_print_box_start: procedure (bg : Integer); cdecl;
  82. php_info_print_box_end: procedure; cdecl;
  83. php_info_print_hr: procedure; cdecl;
  84. php_info_print_table_start: procedure; cdecl;
  85. php_info_print_table_row1: procedure(n1 : integer; c1: pchar); cdecl;
  86. php_info_print_table_row2: procedure (n2 : integer; c1, c2 : pchar); cdecl;
  87. php_info_print_table_row3: procedure (n3 : integer; c1, c2, c3 : pchar); cdecl;
  88. php_info_print_table_row4: procedure (n4 : integer; c1, c2, c3, c4 : pchar); cdecl;
  89. php_info_print_table_row : procedure (n2 : integer; c1, c2 : pchar); cdecl;
  90. php_info_print_table_end: procedure (); cdecl;
  91. php_body_write: function (const str : PChar; str_length: uint; TSRMLS_DC : pointer) : integer; cdecl;
  92. php_header_write: function (const str : PChar; str_length: uint; TSRMLS_DC : pointer) : integer; cdecl;
  93. php_log_err: procedure (err_msg : PChar; TSRMLS_DC : pointer); cdecl;
  94. php_html_puts: procedure (str : PChar; str_len : integer; TSRMLS_DC : pointer); cdecl;
  95. _php_error_log: function (opt_err : integer; msg : PChar; opt: PChar; headers: PChar; TSRMLS_DC : pointer) : integer; cdecl;
  96. php_print_credits: procedure (flag : integer); cdecl;
  97. php_info_print_css: procedure(); cdecl;
  98. php_set_sock_blocking: function (socketd : integer; block : integer; TSRMLS_DC : pointer) : integer; cdecl;
  99. php_copy_file: function (src : PChar; dest : PChar; TSRMLS_DC : pointer) : integer; cdecl;
  100. {$IFDEF PHP4}
  101. php_flock: function (fd : integer; operation : integer) : integer; cdecl;
  102. php_lookup_hostname: function (const addr : PChar; _in : pinaddr ) : integer; cdecl;
  103. {$ENDIF}
  104. php_header: function() : integer; cdecl;
  105. php_setcookie: function (name : PChar; name_len : integer; value : PChar; value_len: integer;
  106. expires : longint; path : PChar; path_len : integer; domain : PChar; domain_len : integer;
  107. secure : integer; TSRMLS_DC : pointer) : integer; cdecl;
  108. var
  109. php_escape_html_entities: function (old : PByte; oldlen : integer; newlen : PINT; all : integer;
  110. quote_style : integer; hint_charset: PChar; TSRMLS_DC : pointer) : pChar; cdecl;
  111. var
  112. php_ini_long: function (name : PChar; name_length : uint; orig : Integer) : Longint; cdecl;
  113. php_ini_double: function(name : PChar; name_length : uint; orig : Integer) : Double; cdecl;
  114. php_ini_string: function(name : PChar; name_length : uint; orig : Integer) : PChar; cdecl;
  115. function zval2variant(value : zval) : variant;
  116. procedure variant2zval(value : variant; z : pzval);
  117. var
  118. php_url_free: procedure (theurl : pphp_url); cdecl;
  119. php_url_parse: function (str : PChar) : pphp_url; cdecl;
  120. php_url_decode: function (str : PChar; len : Integer) : Integer; cdecl;
  121. { return value: length of decoded string }
  122. php_raw_url_decode: function (str : PChar; len : Integer) : Integer; cdecl;
  123. { return value: length of decoded string }
  124. php_url_encode: function (s : PChar; len : Integer; new_length : PInteger) : PChar; cdecl;
  125. php_raw_url_encode: function (s : PChar; len : Integer; new_length : PInteger) : PChar; cdecl;
  126. {$IFDEF PHP510}
  127. php_register_extensions: function (ptr : pointer; count: integer; TSRMLS_DC: pointer) : integer; cdecl;
  128. {$ELSE}
  129. php_startup_extensions: function (ptr: pointer; count : integer) : integer; cdecl;
  130. {$ENDIF}
  131. php_error_docref0: procedure (const docref : PChar; TSRMLS_DC : pointer; _type : integer; const Msg : PChar); cdecl;
  132. php_error_docref: procedure (const docref : PChar; TSRMLS_DC : pointer; _type : integer; const Msg : PChar); cdecl;
  133. php_error_docref1: procedure (const docref : PChar; TSRMLS_DC : pointer; const param1 : PChar; _type: integer; Msg : PChar); cdecl;
  134. php_error_docref2: procedure (const docref : PChar; TSRMLS_DC : pointer; const param1 : PChar; const param2 : PChar; _type : integer; Msg : PChar); cdecl;
  135. function GetPostVariables: pzval;
  136. function GetGetVariables : pzval;
  137. function GetServerVariables : pzval;
  138. function GetEnvVariables : pzval;
  139. function GetFilesVariables : pzval;
  140. function GetPHPGlobals(TSRMLS_DC : pointer) : Pphp_Core_Globals;
  141. function PG(TSRMLS_DC : pointer) : Pphp_Core_Globals;
  142. procedure PHP_FUNCTION(var AFunction : zend_function_entry; AName : PChar; AHandler : pointer);
  143. {$IFDEF PHP4}
  144. function LoadPHP(const DllFileName: string = 'php4ts.dll') : boolean;
  145. {$ELSE}
  146. function LoadPHP(const DllFileName: string = 'php5ts.dll') : boolean;
  147. {$ENDIF}
  148. procedure UnloadPHP;
  149. function PHPLoaded : boolean;
  150. {$IFNDEF QUIET_LOAD}
  151. procedure CheckPHPErrors;
  152. {$ENDIF}
  153. function FloatToValue(Value: Extended): string;
  154. function ValueToFloat(Value : string) : extended;
  155. type
  156. TPHPFileInfo = record
  157. MajorVersion: Word;
  158. MinorVersion: Word;
  159. Release:Word;
  160. Build:Word;
  161. end;
  162. function GetPHPVersion: TPHPFileInfo;
  163. implementation
  164. function PHPLoaded : boolean;
  165. begin
  166. Result := PHPLib <> 0;
  167. end;
  168. procedure UnloadPHP;
  169. var
  170. H : THandle;
  171. begin
  172. H := InterlockedExchange(integer(PHPLib), 0);
  173. if H > 0 then
  174. begin
  175. FreeLibrary(H);
  176. end;
  177. end;
  178. {$IFDEF PHP4}
  179. function GetSymbolsTable(TSRMLS_DC : pointer) : PHashTable;
  180. var
  181. executor_globals : pointer;
  182. executor_globals_value : integer;
  183. executor_hash : PHashTable;
  184. begin
  185. if not PHPLoaded then
  186. begin
  187. Result := nil;
  188. Exit;
  189. end;
  190. executor_globals := GetProcAddress(PHPLib, 'executor_globals_id');
  191. executor_globals_value := integer(executor_globals^);
  192. asm
  193. mov ecx, executor_globals_value
  194. mov edx, dword ptr tsrmls_dc
  195. mov eax, dword ptr [edx]
  196. mov ecx, dword ptr [eax+ecx*4-4]
  197. add ecx, 0DCh
  198. mov executor_hash, ecx
  199. end;
  200. Result := executor_hash;
  201. end;
  202. {$ELSE}
  203. function GetSymbolsTable(TSRMLS_DC : pointer) : PHashTable;
  204. begin
  205. Result := @GetExecutorGlobals(TSRMLS_DC).symbol_table;
  206. end;
  207. {$ENDIF}
  208. function GetTrackHash(Name : string; TSRMLS_DC : pointer) : PHashTable;
  209. var
  210. data : ^ppzval;
  211. arr : PHashTable;
  212. ret : integer;
  213. begin
  214. Result := nil;
  215. {$IFDEF PHP4}
  216. arr := GetSymbolsTable(TSRMLS_DC);
  217. {$ELSE}
  218. arr := @GetExecutorGlobals(TSRMLS_DC).symbol_table;
  219. {$ENDIF}
  220. if Assigned(Arr) then
  221. begin
  222. new(data);
  223. ret := zend_hash_find(arr, PChar(Name), Length(Name)+1, Data);
  224. if ret = SUCCESS then
  225. begin
  226. Result := data^^^.value.ht;
  227. end;
  228. end;
  229. end;
  230. function GetSAPIGlobals(TSRMLS_DC : pointer) : Psapi_globals_struct;
  231. var
  232. sapi_global_id : pointer;
  233. sapi_globals_value : integer;
  234. sapi_globals : Psapi_globals_struct;
  235. begin
  236. Result := nil;
  237. sapi_global_id := GetProcAddress(PHPLib, 'sapi_globals_id');
  238. if Assigned(sapi_global_id) then
  239. begin
  240. sapi_globals_value := integer(sapi_global_id^);
  241. asm
  242. mov ecx, sapi_globals_value
  243. mov edx, dword ptr tsrmls_dc
  244. mov eax, dword ptr [edx]
  245. mov ecx, dword ptr [eax+ecx*4-4]
  246. mov sapi_globals, ecx
  247. end;
  248. Result := sapi_globals;
  249. end;
  250. end;
  251. function zval2variant(value : zval) : variant;
  252. begin
  253. case Value._type of
  254. IS_NULL : Result := NULL;
  255. IS_LONG : Result := Value.value.lval;
  256. IS_DOUBLE : Result := Value.value.dval;
  257. IS_STRING : Result := String(Value.Value.str.val);
  258. IS_BOOL : Result := Boolean(Value.Value.lval);
  259. else
  260. Result := NULL;
  261. end;
  262. end;
  263. procedure variant2zval(value : variant; z : pzval);
  264. var
  265. S : string;
  266. begin
  267. if VarIsEmpty(value) then
  268. begin
  269. ZVAL_NULL(z);
  270. Exit;
  271. end;
  272. case TVarData(Value).VType of
  273. varString : //Peter Enz
  274. begin
  275. if Assigned ( TVarData(Value).VString ) then
  276. begin
  277. ZVAL_STRING(z, TVarData(Value).VString , true);
  278. end
  279. else
  280. begin
  281. ZVAL_STRING(z, '', true);
  282. end;
  283. end;
  284. varOleStr : //Peter Enz
  285. begin
  286. if Assigned ( TVarData(Value).VString ) then
  287. begin
  288. S := Value;
  289. ZVAL_STRING(z, PChar(s), {TVarData(Value).VString, } true);
  290. end
  291. else
  292. begin
  293. ZVAL_STRING(z, '', true);
  294. end;
  295. end;
  296. varSmallInt : ZVAL_LONG(z, TVarData(Value).VSmallint);
  297. varInteger : ZVAL_LONG(z, TVarData(Value).VInteger);
  298. varBoolean : ZVAL_BOOL(z, TVarData(Value).VBoolean);
  299. varSingle : ZVAL_DOUBLE(z, TVarData(Value).VSingle);
  300. varDouble : ZVAL_DOUBLE(z, TVarData(Value).VDouble);
  301. varError : ZVAL_LONG(z, TVarData(Value).VError);
  302. varByte : ZVAL_LONG(z, TVarData(Value).VByte);
  303. varDate : ZVAL_DOUBLE(z, TVarData(Value).VDate);
  304. else
  305. ZVAL_NULL(Z);
  306. end;
  307. end;
  308. function GetPHPGlobals(TSRMLS_DC : pointer) : Pphp_Core_Globals;
  309. var
  310. core_global_id : pointer;
  311. core_globals_value : integer;
  312. core_globals : Pphp_core_globals;
  313. begin
  314. Result := nil;
  315. core_global_id := GetProcAddress(PHPLib, 'core_globals_id');
  316. if Assigned(core_global_id) then
  317. begin
  318. core_globals_value := integer(core_global_id^);
  319. asm
  320. mov ecx, core_globals_value
  321. mov edx, dword ptr tsrmls_dc
  322. mov eax, dword ptr [edx]
  323. mov ecx, dword ptr [eax+ecx*4-4]
  324. mov core_globals, ecx
  325. end;
  326. Result := core_globals;
  327. end;
  328. end;
  329. function PG(TSRMLS_DC : pointer) : Pphp_Core_Globals;
  330. begin
  331. result := GetPHPGlobals(TSRMLS_DC);
  332. end;
  333. procedure PHP_FUNCTION(var AFunction : zend_function_entry; AName : PChar; AHandler : pointer);
  334. begin
  335. AFunction.fname := AName;
  336. AFunction.handler := AHandler;
  337. {$IFDEF PHP4}
  338. AFunction.func_arg_types := nil;
  339. {$ELSE}
  340. AFunction.arg_info := nil;
  341. {$ENDIF}
  342. end;
  343. procedure phperror(Error : PChar);
  344. begin
  345. zend_error(E_PARSE, Error);
  346. end;
  347. {$IFDEF PHP4}
  348. function LoadPHP(const DllFileName: string = 'php4ts.dll') : boolean;
  349. {$ELSE}
  350. function LoadPHP(const DllFileName: string = 'php5ts.dll') : boolean;
  351. {$ENDIF}
  352. begin
  353. Result := false;
  354. if not PHPLoaded then
  355. begin
  356. if not LoadZend(DllFileName) then
  357. Exit;
  358. end;
  359. sapi_add_header_ex := GetProcAddress(PHPLib, 'sapi_add_header_ex');
  360. php_request_startup := GetProcAddress(PHPLib, 'php_request_startup');
  361. php_request_shutdown := GetProcAddress(PHPLib, 'php_request_shutdown');
  362. php_module_startup := GetProcAddress(PHPLib, 'php_module_startup');
  363. php_module_shutdown := GetProcAddress(PHPLib, 'php_module_shutdown');
  364. php_module_shutdown_wrapper := GetProcAddress(PHPLib, 'php_module_shutdown_wrapper');
  365. sapi_startup := GetProcAddress(PHPLib, 'sapi_startup');
  366. sapi_shutdown := GetProcAddress(PHPLib, 'sapi_shutdown');
  367. sapi_activate := GetProcAddress(PHPLib, 'sapi_activate');
  368. sapi_deactivate := GetProcAddress(PHPLib, 'sapi_deactivate');
  369. php_execute_script := GetProcAddress(PHPLib, 'php_execute_script');
  370. php_handle_aborted_connection := GetProcAddress(PHPLib, 'php_handle_aborted_connection');
  371. php_register_variable := GetProcAddress(PHPLib, 'php_register_variable');
  372. php_register_variable_safe := GetProcAddress(PHPLib, 'php_register_variable_safe');
  373. php_register_variable_ex := GetProcAddress(PHPLib, 'php_register_variable_ex');
  374. php_output_startup := GetProcAddress(PHPLib, 'php_output_startup');
  375. php_output_activate := GetProcAddress(PHPLib, 'php_output_activate');
  376. php_output_set_status := GetProcAddress(PHPLib, 'php_output_set_status');
  377. php_output_register_constants := GetProcAddress(PHPLib, 'php_output_register_constants');
  378. php_start_ob_buffer := GetProcAddress(PHPLib, 'php_start_ob_buffer');
  379. php_start_ob_buffer_named := GetProcAddress(PHPLib, 'php_start_ob_buffer_named');
  380. php_end_ob_buffer := GetProcAddress(PHPLib, 'php_end_ob_buffer');
  381. php_end_ob_buffers := GetProcAddress(PHPLib, 'php_end_ob_buffers');
  382. php_ob_get_buffer := GetProcAddress(PHPLib, 'php_ob_get_buffer');
  383. php_ob_get_length := GetProcAddress(PHPLib, 'php_ob_get_length');
  384. php_start_implicit_flush := GetProcAddress(PHPLib, 'php_start_implicit_flush');
  385. php_end_implicit_flush := GetProcAddress(PHPLib, 'php_end_implicit_flush');
  386. php_get_output_start_filename := GetProcAddress(PHPLib, 'php_get_output_start_filename');
  387. php_get_output_start_lineno := GetProcAddress(PHPLib, 'php_get_output_start_lineno');
  388. php_ob_handler_used := GetProcAddress(PHPLib, 'php_ob_handler_used');
  389. php_ob_init_conflict := GetProcAddress(PHPLib, 'php_ob_init_conflict');
  390. php_strtoupper := GetProcAddress(PHPLib, 'php_strtoupper');
  391. php_strtolower := GetProcAddress(PHPLib, 'php_strtolower');
  392. php_strtr := GetProcAddress(PHPLib, 'php_strtr');
  393. php_stripcslashes := GetProcAddress(PHPLib, 'php_stripcslashes');
  394. php_basename := GetProcAddress(PHPLib, 'php_basename');
  395. php_dirname := GetProcAddress(PHPLib, 'php_dirname');
  396. php_stristr := GetProcAddress(PHPLib, 'php_stristr');
  397. php_str_to_str := GetProcAddress(PHPLib, 'php_str_to_str');
  398. php_strip_tags := GetProcAddress(PHPLib, 'php_strip_tags');
  399. php_implode := GetProcAddress(PHPLib, 'php_implode');
  400. php_explode := GetProcAddress(PHPLib, 'php_explode');
  401. php_info_html_esc := GetProcAddress(PHPLib, 'php_info_html_esc');
  402. php_print_info_htmlhead := GetProcAddress(PHPLib, 'php_print_info_htmlhead');
  403. php_print_info := GetProcAddress(PHPLib, 'php_print_info');
  404. php_info_print_table_colspan_header := GetProcAddress(PHPLib, 'php_info_print_table_colspan_header');
  405. php_info_print_box_start := GetProcAddress(PHPLib, 'php_info_print_box_start');
  406. php_info_print_box_end := GetProcAddress(PHPLib, 'php_info_print_box_end');
  407. php_info_print_hr := GetProcAddress(PHPLib, 'php_info_print_hr');
  408. php_info_print_table_start := GetProcAddress(PHPLib, 'php_info_print_table_start');
  409. php_info_print_table_row1 := GetProcAddress(PHPLib, 'php_info_print_table_row');
  410. php_info_print_table_row2 := GetProcAddress(PHPLib, 'php_info_print_table_row');
  411. php_info_print_table_row3 := GetProcAddress(PHPLib, 'php_info_print_table_row');
  412. php_info_print_table_row4 := GetProcAddress(PHPLib, 'php_info_print_table_row');
  413. php_info_print_table_row := GetProcAddress(PHPLib, 'php_info_print_table_row');
  414. php_info_print_table_end := GetProcAddress(PHPLib, 'php_info_print_table_end');
  415. php_body_write := GetProcAddress(PHPLib, 'php_body_write');
  416. php_header_write := GetProcAddress(PHPLib, 'php_header_write');
  417. php_log_err := GetProcAddress(PHPLib, 'php_log_err');
  418. php_html_puts := GetProcAddress(PHPLib, 'php_html_puts');
  419. _php_error_log := GetProcAddress(PHPLib, '_php_error_log');
  420. php_print_credits := GetProcAddress(PHPLib, 'php_print_credits');
  421. php_info_print_css := GetProcAddress(PHPLib, 'php_info_print_css');
  422. php_set_sock_blocking := GetProcAddress(PHPLib, 'php_set_sock_blocking');
  423. php_copy_file := GetProcAddress(PHPLib, 'php_copy_file');
  424. {$IFDEF PHP4}
  425. php_flock := GetProcAddress(PHPLib, 'php_flock');
  426. php_lookup_hostname := GetProcAddress(PHPLib, 'php_lookup_hostname');
  427. {$ENDIF}
  428. php_header := GetProcAddress(PHPLib, 'php_header');
  429. php_setcookie := GetProcAddress(PHPLib, 'php_setcookie');
  430. php_escape_html_entities := GetProcAddress(PHPLib, 'php_escape_html_entities');
  431. php_ini_long := GetProcAddress(PHPLib, 'zend_ini_long');
  432. php_ini_double := GetProcAddress(PHPLib, 'zend_ini_double');
  433. php_ini_string := GetProcAddress(PHPLib, 'zend_ini_string');
  434. php_url_free := GetProcAddress(PHPLib, 'php_url_free');
  435. php_url_parse := GetProcAddress(PHPLib, 'php_url_parse');
  436. php_url_decode := GetProcAddress(PHPLib, 'php_url_decode');
  437. php_raw_url_decode := GetProcAddress(PHPLib, 'php_raw_url_decode');
  438. php_url_encode := GetProcAddress(PHPLib, 'php_url_encode');
  439. php_raw_url_encode := GetProcAddress(PHPLib, 'php_raw_url_encode');
  440. {$IFDEF PHP510}
  441. php_register_extensions := GetProcAddress(PHPLib, 'php_register_extensions');
  442. {$ELSE}
  443. php_startup_extensions := GetProcAddress(PHPLib, 'php_startup_extensions');
  444. {$ENDIF}
  445. php_error_docref0 := GetProcAddress(PHPLib, 'php_error_docref0');
  446. php_error_docref := GetProcAddress(PHPLib, 'php_error_docref0');
  447. php_error_docref1 := GetProcAddress(PHPLib, 'php_error_docref1');
  448. php_error_docref2 := GetProcAddress(PHPLib, 'php_error_docref2');
  449. {$IFNDEF QUIET_LOAD}
  450. CheckPHPErrors;
  451. {$ENDIF}
  452. Result := true;
  453. end;
  454. {$IFNDEF QUIET_LOAD}
  455. procedure CheckPHPErrors;
  456. begin
  457. if @sapi_add_header_ex = nil then raise EPHP4DelphiException.Create('sapi_add_header_ex');
  458. if @php_request_startup = nil then raise EPHP4DelphiException.Create('php_request_startup');
  459. if @php_request_shutdown = nil then raise EPHP4DelphiException.Create('php_request_shutdown');
  460. if @php_module_startup = nil then raise EPHP4DelphiException.Create('php_module_startup');
  461. if @php_module_shutdown = nil then raise EPHP4DelphiException.Create('php_module_shutdown');
  462. if @php_module_shutdown_wrapper = nil then raise EPHP4DelphiException.Create('php_module_shutdown_wrapper');
  463. if @sapi_startup = nil then raise EPHP4DelphiException.Create('sapi_startup');
  464. if @sapi_shutdown = nil then raise EPHP4DelphiException.Create('sapi_shutdown');
  465. if @sapi_activate = nil then raise EPHP4DelphiException.Create('sapi_activate');
  466. if @sapi_deactivate = nil then raise EPHP4DelphiException.Create('sapi_deactivate');
  467. if @php_execute_script = nil then raise EPHP4DelphiException.Create('php_execute_script');
  468. if @php_handle_aborted_connection = nil then raise EPHP4DelphiException.Create('php_handle_aborted_connection');
  469. if @php_register_variable = nil then raise EPHP4DelphiException.Create('php_register_variable');
  470. if @php_register_variable_safe = nil then raise EPHP4DelphiException.Create('php_register_variable_safe');
  471. if @php_register_variable_ex = nil then raise EPHP4DelphiException.Create('php_register_variable_ex');
  472. if @php_output_startup = nil then raise EPHP4DelphiException.Create('php_output_startup');
  473. if @php_output_activate = nil then raise EPHP4DelphiException.Create('php_output_activate');
  474. if @php_output_set_status = nil then raise EPHP4DelphiException.Create('php_output_set_status');
  475. if @php_output_register_constants = nil then raise EPHP4DelphiException.Create('php_output_register_constants');
  476. if @php_start_ob_buffer = nil then raise EPHP4DelphiException.Create('php_start_ob_buffer');
  477. if @php_start_ob_buffer_named = nil then raise EPHP4DelphiException.Create('php_start_ob_buffer_named');
  478. if @php_end_ob_buffer = nil then raise EPHP4DelphiException.Create('php_end_ob_buffer');
  479. if @php_end_ob_buffers = nil then raise EPHP4DelphiException.Create('php_end_ob_buffers');
  480. if @php_ob_get_buffer = nil then raise EPHP4DelphiException.Create('php_ob_get_buffer');
  481. if @php_ob_get_length = nil then raise EPHP4DelphiException.Create('php_ob_get_length');
  482. if @php_start_implicit_flush = nil then raise EPHP4DelphiException.Create('php_start_implicit_flush');
  483. if @php_end_implicit_flush = nil then raise EPHP4DelphiException.Create('php_end_implicit_flush');
  484. if @php_get_output_start_filename = nil then raise EPHP4DelphiException.Create('php_get_output_start_filename');
  485. if @php_get_output_start_lineno = nil then raise EPHP4DelphiException.Create('php_get_output_start_lineno');
  486. if @php_ob_handler_used = nil then raise EPHP4DelphiException.Create('php_ob_handler_used');
  487. if @php_ob_init_conflict = nil then raise EPHP4DelphiException.Create('php_ob_init_conflict');
  488. if @php_strtoupper = nil then raise EPHP4DelphiException.Create('php_strtoupper');
  489. if @php_strtolower = nil then raise EPHP4DelphiException.Create('php_strtolower');
  490. if @php_strtr = nil then raise EPHP4DelphiException.Create('php_strtr');
  491. if @php_stripcslashes = nil then raise EPHP4DelphiException.Create('php_stripcslashes');
  492. if @php_basename = nil then raise EPHP4DelphiException.Create('php_basename');
  493. if @php_dirname = nil then raise EPHP4DelphiException.Create('php_dirname');
  494. if @php_stristr = nil then raise EPHP4DelphiException.Create('php_stristr');
  495. if @php_str_to_str = nil then raise EPHP4DelphiException.Create('php_str_to_str');
  496. if @php_strip_tags = nil then raise EPHP4DelphiException.Create('php_strip_tags');
  497. if @php_implode = nil then raise EPHP4DelphiException.Create('php_implode');
  498. if @php_explode = nil then raise EPHP4DelphiException.Create('php_explode');
  499. if @php_info_html_esc = nil then raise EPHP4DelphiException.Create('php_info_html_esc');
  500. if @php_print_info_htmlhead = nil then raise EPHP4DelphiException.Create('php_print_info_htmlhead');
  501. if @php_print_info = nil then raise EPHP4DelphiException.Create('php_print_info');
  502. if @php_info_print_table_colspan_header = nil then raise EPHP4DelphiException.Create('php_info_print_table_colspan_header');
  503. if @php_info_print_box_start = nil then raise EPHP4DelphiException.Create('php_info_print_box_start');
  504. if @php_info_print_box_end = nil then raise EPHP4DelphiException.Create('php_info_print_box_end');
  505. if @php_info_print_hr = nil then raise EPHP4DelphiException.Create('php_info_print_hr');
  506. if @php_info_print_table_start = nil then raise EPHP4DelphiException.Create('php_info_print_table_start');
  507. if @php_info_print_table_row1 = nil then raise EPHP4DelphiException.Create('php_info_print_table_row1');
  508. if @php_info_print_table_row2 = nil then raise EPHP4DelphiException.Create('php_info_print_table_row2');
  509. if @php_info_print_table_row3 = nil then raise EPHP4DelphiException.Create('php_info_print_table_row3');
  510. if @php_info_print_table_row4 = nil then raise EPHP4DelphiException.Create('php_info_print_table_row4');
  511. if @php_info_print_table_row = nil then raise EPHP4DelphiException.Create('php_info_print_table_row');
  512. if @php_info_print_table_end = nil then raise EPHP4DelphiException.Create('php_info_print_table_end');
  513. if @php_body_write = nil then raise EPHP4DelphiException.Create('php_body_write');
  514. if @php_header_write = nil then raise EPHP4DelphiException.Create('php_header_write');
  515. if @php_log_err = nil then raise EPHP4DelphiException.Create('php_log_err');
  516. if @php_html_puts = nil then raise EPHP4DelphiException.Create('php_html_puts');
  517. if @_php_error_log = nil then raise EPHP4DelphiException.Create('_php_error_log');
  518. if @php_print_credits = nil then raise EPHP4DelphiException.Create('php_print_credits');
  519. if @php_info_print_css = nil then raise EPHP4DelphiException.Create('php_info_print_css');
  520. if @php_set_sock_blocking = nil then raise EPHP4DelphiException.Create('php_set_sock_blocking');
  521. if @php_copy_file = nil then raise EPHP4DelphiException.Create('php_copy_file');
  522. {$IFDEF PHP4}
  523. if @php_flock = nil then raise EPHP4DelphiException.Create('php_flock');
  524. if @php_lookup_hostname = nil then raise EPHP4DelphiException.Create('php_lookup_hostname');
  525. {$ENDIF}
  526. if @php_header = nil then raise EPHP4DelphiException.Create('php_header');
  527. if @php_setcookie = nil then raise EPHP4DelphiException.Create('php_setcookie');
  528. if @php_escape_html_entities = nil then raise EPHP4DelphiException.Create('php_escape_html_entities');
  529. if @php_ini_long = nil then raise EPHP4DelphiException.Create('php_ini_long');
  530. if @php_ini_double = nil then raise EPHP4DelphiException.Create('php_ini_double');
  531. if @php_ini_string = nil then raise EPHP4DelphiException.Create('php_ini_string');
  532. if @php_url_free = nil then raise EPHP4DelphiException.Create('php_url_free');
  533. if @php_url_parse = nil then raise EPHP4DelphiException.Create('php_url_parse');
  534. if @php_url_decode = nil then raise EPHP4DelphiException.Create('php_url_decode');
  535. if @php_raw_url_decode = nil then raise EPHP4DelphiException.Create('php_raw_url_decode');
  536. if @php_url_encode = nil then raise EPHP4DelphiException.Create('php_url_encode');
  537. if @php_raw_url_encode = nil then raise EPHP4DelphiException.Create('php_raw_url_encode');
  538. if @php_startup_extensions = nil then raise EPHP4DelphiException.Create('php_startup_extensions');
  539. if @php_error_docref0 = nil then raise EPHP4DelphiException.Create('php_error_docref0');
  540. if @php_error_docref = nil then raise EPHP4DelphiException.Create('php_error_docref');
  541. if @php_error_docref1 = nil then raise EPHP4DelphiException.Create('php_error_docref1');
  542. if @php_error_docref2 = nil then raise EPHP4DelphiException.Create('php_error_docref2');
  543. end;
  544. {$ENDIF}
  545. function GetPostVariables: pzval;
  546. var
  547. TSRMLS_D : pointer;
  548. CoreGlobals : Pphp_Core_Globals;
  549. begin
  550. TSRMLS_D := ts_resource_ex(0, nil);
  551. CoreGlobals := PG(TSRMLS_D);
  552. Result := CoreGlobals^.http_globals[0];
  553. end;
  554. function GetGetVariables : pzval;
  555. var
  556. TSRMLS_D : pointer;
  557. CoreGlobals : Pphp_Core_Globals;
  558. begin
  559. TSRMLS_D := ts_resource_ex(0, nil);
  560. CoreGlobals := PG(TSRMLS_D);
  561. Result := CoreGlobals^.http_globals[1];
  562. end;
  563. function GetServerVariables : pzval;
  564. var
  565. TSRMLS_D : pointer;
  566. CoreGlobals : Pphp_Core_Globals;
  567. begin
  568. TSRMLS_D := ts_resource_ex(0, nil);
  569. CoreGlobals := PG(TSRMLS_D);
  570. Result := CoreGlobals^.http_globals[3];
  571. end;
  572. function GetEnvVariables : pzval;
  573. var
  574. TSRMLS_D : pointer;
  575. CoreGlobals : Pphp_Core_Globals;
  576. begin
  577. TSRMLS_D := ts_resource_ex(0, nil);
  578. CoreGlobals := PG(TSRMLS_D);
  579. Result := CoreGlobals^.http_globals[4];
  580. end;
  581. function GetFilesVariables : pzval;
  582. var
  583. TSRMLS_D : pointer;
  584. CoreGlobals : Pphp_Core_Globals;
  585. begin
  586. TSRMLS_D := ts_resource_ex(0, nil);
  587. CoreGlobals := PG(TSRMLS_D);
  588. Result := CoreGlobals^.http_globals[5];
  589. end;
  590. function FloatToValue(Value: Extended): string;
  591. var
  592. c: Char;
  593. begin
  594. c := DecimalSeparator;
  595. DecimalSeparator := '.';
  596. Result := SysUtils.FormatFloat('0.####', Value);
  597. DecimalSeparator := c;
  598. end;
  599. function ValueToFloat(Value : string) : extended;
  600. var
  601. c: Char;
  602. begin
  603. c := DecimalSeparator;
  604. DecimalSeparator := '.';
  605. Result := SysUtils.StrToFloat(Value);
  606. DecimalSeparator := c;
  607. end;
  608. function GetPHPVersion: TPHPFileInfo;
  609. var
  610. FileName: string;
  611. InfoSize, Wnd: DWORD;
  612. VerBuf: Pointer;
  613. FI: PVSFixedFileInfo;
  614. VerSize: DWORD;
  615. begin
  616. Result.MajorVersion := 0;
  617. Result.MinorVersion := 0;
  618. Result.Release := 0;
  619. Result.Build := 0;
  620. {$IFDEF PHP4}
  621. FileName := 'php4ts.dll';
  622. {$ELSE}
  623. FileName := 'php5ts.dll';
  624. {$ENDIF}
  625. InfoSize := GetFileVersionInfoSize(PChar(FileName), Wnd);
  626. if InfoSize <> 0 then
  627. begin
  628. GetMem(VerBuf, InfoSize);
  629. try
  630. if GetFileVersionInfo(PChar(FileName), Wnd, InfoSize, VerBuf) then
  631. if VerQueryValue(VerBuf, '\', Pointer(FI), VerSize) then
  632. begin
  633. Result.MajorVersion := HIWORD(FI.dwFileVersionMS);
  634. Result.MinorVersion := LOWORD(FI.dwFileVersionMS);
  635. Result.Release := HIWORD(FI.dwFileVersionLS);
  636. Result.Build := LOWORD(FI.dwFileVersionLS);
  637. end;
  638. finally
  639. FreeMem(VerBuf);
  640. end;
  641. end;
  642. end;
  643. initialization
  644. {$IFDEF PHP4DELPHI_AUTOLOAD}
  645. LoadPHP;
  646. {$ENDIF}
  647. finalization
  648. {$IFDEF PHP4DELPHI_AUTOUNLOAD}
  649. UnloadPHP;
  650. {$ENDIF}
  651. end.