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