Форум по Delphi программированию

Delphi Sources



Вернуться   Форум по Delphi программированию > Все о Delphi > [ "Начинающим" ]
Ник
Пароль
Регистрация <<         Правила форума         >> FAQ Пользователи Календарь Поиск Сообщения за сегодня Все разделы прочитаны

Ответ
 
Опции темы Поиск в этой теме Опции просмотра
  #1  
Старый 29.03.2021, 14:10
Аватар для who_know777
who_know777 who_know777 вне форума
Прохожий
 
Регистрация: 09.02.2021
Сообщения: 5
Версия Delphi: Delphi 7
Репутация: 10
По умолчанию Выполнение php кода в delphi

Доброго времени суток!

Скачал архив с php интерпертатором, с официального сайта.

Передаю через командную строку имя php скрипта через delphi,
для выполнения, скрипт выполняется. Передаю get параметры, все ок.

Не могу понять, как отправлять и получать post параметры. Помогите пожалуйста.

Код:
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
var
  s: string;
begin
  s := Path('php\php.exe ');
  s := s + Path('index.php');
 
  TextToWebBrowser(WebBrowser1, GetDosOutput(s));
end.
 
function Path(s: string): string;
begin
  Result := PathAppend(ExtractFilePath(paramstr(0)), s);
end; //Path
 
function PathAppend(path, str: string): string;
begin
  if path[Length(path)] <> '\' then path := path + '\';
  result := path + str;
end; //PathAppend 
 
procedure TextToWebBrowser(WB: TWebBrowser; Text: string);
var            
  V: OleVariant;
  Document: IHTMLDocument2;
begin
   if WB.Document = nil then WB.Navigate('about<b></b>:blank');
   while WB.Document = nil do Application.ProcessMessages;
   Document := WB.Document as IHtmlDocument2;
   V := VarArrayCreate([0, 0], varVariant);
   V[0] := Text;
   Document.Write(PSafeArray(TVarData(v).VArray));
   Document.Close;
end; //TextToWebBrowser
 
function GetDosOutput(DosApp: String): string;
const
  ReadBuffer = 2400;
var
  Buffer: PChar;
  BytesRead: DWord;
  Apprunning: DWord;    
  start: TStartUpInfo;   
  ReadPipe, WritePipe: THandle; 
  Security: TSecurityAttributes;
  ProcessInfo: TProcessInformation;
begin
  result := '';
   
  with Security do
  begin
    nlength := SizeOf(TSecurityAttributes);
    binherithandle := true;
    lpsecuritydescriptor := nil;
  end;
 
  if Createpipe(ReadPipe, WritePipe, @Security, 0) then
  begin
    Buffer  := AllocMem(ReadBuffer + 1);
    FillChar(Start,Sizeof(Start),#0);
    start.cb          := SizeOf(start);
    start.hStdOutput  := WritePipe;
    start.hStdInput   := ReadPipe;
    start.dwFlags     := STARTF_USESTDHANDLES +
                         STARTF_USESHOWWINDOW;
    start.wShowWindow := SW_HIDE;
 
    if CreateProcess(nil,
          PChar(DosApp),
          @Security,
          @Security,
          true,
          NORMAL_PRIORITY_CLASS,
          nil,
          nil,
          start,
          ProcessInfo)
    then
    begin
      repeat
        Apprunning := WaitForSingleObject(ProcessInfo.hProcess, 100);
        Application.ProcessMessages;
      until (Apprunning <> WAIT_TIMEOUT);
      repeat
        BytesRead := 0;
        ReadFile(ReadPipe, Buffer[0], ReadBuffer, BytesRead, nil);
        Buffer[BytesRead]:= #0;
       //OemToAnsi(Buffer,Buffer);
        result := result + String(Buffer);
      until (BytesRead < ReadBuffer);
    end;
    CloseHandle(ProcessInfo.hProcess);
    CloseHandle(ProcessInfo.hThread);
    CloseHandle(ReadPipe);
    CloseHandle(WritePipe);  
    FreeMem(Buffer);
  end;
end;

Последний раз редактировалось who_know777, 29.03.2021 в 14:40.
Ответить с цитированием
Ответ


Delphi Sources

Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск
Опции просмотра

Ваши права в разделе
Вы не можете создавать темы
Вы не можете отвечать на сообщения
Вы не можете прикреплять файлы
Вы не можете редактировать сообщения

BB-коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход


Часовой пояс GMT +3, время: 13:23.


 

Сайт

Форум

FAQ

Соглашения

Прочее

 

Copyright © Форум "Delphi Sources" by BrokenByte Software, 2004-2025