|
-
Sep 30th, 2001, 03:59 PM
#1
Thread Starter
Addicted Member
Get the returned values from PHP
Hi all!
I don't know if you get my last thread so I repost it again.
Please give an answer - even tho you're not sure about it.
I need your help! Please!
I want to execute a PHP-Script thru my "Webserver" but just executing the interpreter wouldn't bring anything I suppose.
So what do I have to do, to tell the interpreter to execute a script and also get its output?? How to set values in PHP like $HTTP_SERVER_VARS etc.
The webserver is a small http/1.1 compatible webserver programed in VB6 with Winsock.
I am using PHP 4.0.6 in c:/php/php.exe .
Thanks in advance,
dmr.
Code that I author is neither elegant nor efficient. It is, however, functional. Once I get something that works, I'm generally satisfied with myself - I mean, if it works, that's good enough, right?
Originally posted by aknisely
Sorry, but I feel uncomfortable on CC with clothes on
__________________
The truth ... is out there!
-
Sep 30th, 2001, 04:01 PM
#2
PowerPoster
What does this look like??!! A PHP forum??! 
Try this one instead http://www.vbforums.com/forumdisplay.php?forumid=11
-
Sep 30th, 2001, 04:16 PM
#3
Frenzied Member
http://www.ipdg3.com/ is not a real active spot but they do have a good selection of forums dedicated to PHP.
Greg
Free VB Add-In - The Reference Librarian
Click Here for screen shot and download link.
-
Sep 30th, 2001, 04:44 PM
#4
Thread Starter
Addicted Member
Infact it is NOT a PHP-Question.
I bet that those who are in the PHP-Forum don't even know what VB is... 
It is a question to get the returned value from an executed program - in this case php.exe - through another program - a VB-program.
So. Any ideas??
Tia.
Code that I author is neither elegant nor efficient. It is, however, functional. Once I get something that works, I'm generally satisfied with myself - I mean, if it works, that's good enough, right?
Originally posted by aknisely
Sorry, but I feel uncomfortable on CC with clothes on
__________________
The truth ... is out there!
-
Sep 30th, 2001, 04:46 PM
#5
PowerPoster
Sorry, but to be honest I only read the subject, so too did Greg by the looks of it
-
Sep 30th, 2001, 05:19 PM
#6
Frenzied Member
Well, when I execute APS pages through VB I connect via port 80 to the server and then GET the ASP page (and pass it paramers) just as I would an HTML page. Since I'm connected to port 80 I just wait for a response from the web server.
How are you calling the PHP page (show code)
Greg
Free VB Add-In - The Reference Librarian
Click Here for screen shot and download link.
-
Sep 30th, 2001, 05:23 PM
#7
Frenzied Member
PS: Is PHP.EXE configured correctly? Even if you are not running WinNT this may help.
NOTE: I'll assume the following in the instructions:
* Windows NT is installed in C:\WINNT
* Your IIS webroot is at C:\INETPUB\WWWROOT
* You have decompressed the PHP files to C:\PHP
* You will use the extension .PHP for your PHP files [Others use extensions like .PHTML, .CGI, .PHP4, etc.]
Adjust accordingly.
____________________________________________________________
1. Download the PHP .zip file from www.php.net or www.zend.com.
____________________________________________________________
2. Decompress the contents of the .zip file to the directory C:\PHP.
____________________________________________________________
3. Move the MSCVRT.DLL and PHP4TS.DLL files in C:\PHP to C:\WINNT\SYSTEM32.
____________________________________________________________
4. Copy C:\PHP\PHP.INI-DIST to C:\PHP\PHP.INI, then move C:\PHP\PHP.INI to C:\WINNT\PHP.INI.
____________________________________________________________
5. Modify C:\WINNT\PHP.INI so that the information contained in it reflects your environment. This will require reading through the PHP.INI file and learning what the various parameters mean, but for starters find and modify the following:
doc_root = "C:\INETPUB\WWWROOT"
extension_dir = "C:\PHP"
Later, as you become more familiar with PHP, be sure to go back to C:\WINNT\PHP.INI and look at sections such as
...
[mail function]
...
[Sessions]
...
and modify them accordingly so that you can start using some of the cooler features in PHP.
____________________________________________________________
6. Run the MMC.
____________________________________________________________
7. Right-click on the webserver you wish to have PHP support added to.
____________________________________________________________
8. Select Properties from the popup menu.
____________________________________________________________
9. In the dialog box that appears (which has 2 rows of tabs), click on the "ISAPI Filters" tab and make sure you do NOT have a filter in place that uses the php4isapi.dll file. If there are any, delete them.
____________________________________________________________
10. Click on the "Home Directory" tab, then click on the [Configuration...] button.
____________________________________________________________
11. Click on the "App Mappings" tab and see whether you have a mapping for the extension ".php".
____________________________________________________________
12. If the mapping already exists, click on that mapping to select it and click the [Edit] button. If the mapping does NOT yet exist, click the [Add...] button.
____________________________________________________________
13. In the dialog box that comes up, be sure that it reads
+-------------------------------------------------
| Add/Edit Application Extension Mapping
+-------------------------------------------------
| Executable: C:\PHP\php.exe %s %s
| Extension: .php
| Method Exclusions:
| [x] Script engine
| [x] Check that file exists [OK] [Cancel] [Help]
+-------------------------------------------------
____________________________________________________________
14. Click [OK] 3 times to save the changes you have just made. You can now exit the MMC.
____________________________________________________________
15. Though not absolutely necessary, if possible, reboot NT or shutdown/restart the w3svc (using "net stop iisadmin" and "net start w3svc" from a Command Prompt).
At this point, your box should be configured for PHP. To test, create a file called C:\INETPUB\WWWROOT\TEST.PHP which reads
<?
phpinfo();
?>
and then view it in your browser by entering
http://site/test.php
where "site" is either the IP address of the NT box, it's DNS name, or the word "localhost" if you are using a browser on the same box.
This should generate a page full of information on the installed version of PHP.
Greg
Free VB Add-In - The Reference Librarian
Click Here for screen shot and download link.
-
Sep 30th, 2001, 05:45 PM
#8
Thread Starter
Addicted Member
Thank you Greg, but I don't think that will help me. 
I'm not quite sure if you get exactly what I mean so I try to explain it more clearly:
My OS is Win2k.
I'm using PHP 4.0.6 (correctly configured and so on) with Apache 1.3.20 (also working fine). So that is not the problem.
I have build my own webserver for implementation in another program and it needs to support PHP (CGI as well).
So how do I execute the PHP-Script and how will it get those variables like $HTTP_GET_VARS ? PHP can't read'em out it self so I have to tell him what has been send via POST or GET and so on.
And when it has done its work how do I get the result? I don't think PHP creates some files with the output or something like that...
Will the normal Shell work? I don't think so.
Thanks in advance,
dmr.
Code that I author is neither elegant nor efficient. It is, however, functional. Once I get something that works, I'm generally satisfied with myself - I mean, if it works, that's good enough, right?
Originally posted by aknisely
Sorry, but I feel uncomfortable on CC with clothes on
__________________
The truth ... is out there!
-
Sep 30th, 2001, 06:51 PM
#9
Frenzied Member
Sorry, I am clueless as to what you want.
Gre
Free VB Add-In - The Reference Librarian
Click Here for screen shot and download link.
-
Oct 1st, 2001, 06:21 AM
#10
Black Cat
You want to put CGI functionality into your web server?
Well, I think your server would have to run the .exe file with its standard input, standard output, and environmental variables "remapped" (not sure of the best term, and I'm not exactly sure how to implement that). Then the cgi app just writes to standard output, which goes to the web server instead of the screen, and that pretty gets sent as the http response (the web server might do some processing, like add extra http headers, etc). The web server places the cgi environmental variables into the standard environmental variable table for the cgi app, so the cgi app can read them thru it's languages method (like the GetEnvironmentVariable API call for C or VB). Finally, I believe incoming form POST data is encoded and placed into standard input, which the cgi app can read from.
Josh
Get these: Mozilla Opera OpenBSD
I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.
-
Oct 1st, 2001, 06:47 AM
#11
Thread Starter
Addicted Member
Thanks, Josh.
That is what I want to do.
But indeed the question is not what but how?
So how will I do that? How can I execute PHP/CGI, transmit the environment, and get the response?
Any ideas?
Tia.
Code that I author is neither elegant nor efficient. It is, however, functional. Once I get something that works, I'm generally satisfied with myself - I mean, if it works, that's good enough, right?
Originally posted by aknisely
Sorry, but I feel uncomfortable on CC with clothes on
__________________
The truth ... is out there!
-
Oct 1st, 2001, 07:12 AM
#12
Black Cat
Based on a quick skim of MSDN, I believe under Windows you can use the CreateProcess API call, and then something like SetStdHandle to redirect std in/out.
Josh
Get these: Mozilla Opera OpenBSD
I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.
-
Oct 1st, 2001, 08:13 AM
#13
Conquistador
please don't yell at me for posting again dmr but i have a small suggestion...
In the php.ini file which comes with PHP, there was this:
; You can redirect all of the output of your scripts to a function. For
; example, if you set output_handler to "ob_gzhandler", output will be
; transparently compressed for browsers that support gzip or deflate encoding.
; Setting an output handler automatically turns on output buffering.
output_handler =
i don't know if it would help, but i thought that might be of some use as you might be able to send the output to a function then to your web server...
If you are really desperate you could check how Apache does it - as it is open source (i think it's written in C++ though ), then try to implement that method into your application....
cya
-
Oct 1st, 2001, 09:29 AM
#14
Thread Starter
Addicted Member
Originally posted by JoshT
Based on a quick skim of MSDN, I believe under Windows you can use the CreateProcess API call, and then something like SetStdHandle to redirect std in/out.
Thanks Josh,
CreateProcess was a good tip but in MSDN I didn't find anything that looks quite useful... 
Btw: There is no API called SetStdHandle but one which is called GetStdHandle but I wasn't able to discover its use. There are several Console-API's might they help me? And when how?
Code that I author is neither elegant nor efficient. It is, however, functional. Once I get something that works, I'm generally satisfied with myself - I mean, if it works, that's good enough, right?
Originally posted by aknisely
Sorry, but I feel uncomfortable on CC with clothes on
__________________
The truth ... is out there!
-
Oct 1st, 2001, 09:38 AM
#15
Thread Starter
Addicted Member
Originally posted by da_silvy
please don't yell at me for posting again dmr but i have a small suggestion...
In the php.ini file which comes with PHP, there was this:
i don't know if it would help, but i thought that might be of some use as you might be able to send the output to a function then to your web server...
If you are really desperate you could check how Apache does it - as it is open source (i think it's written in C++ though ), then try to implement that method into your application....
cya
Thanks Dave for your reply.
I think today I won't close the thread 
Ok. I tried to get an overview from Apache Src but I'm fed up with this code by now. After a couple of hours I think I found the functions which are responsible for executing CGI/PHP but I didn't get where the are exactly transmitting the content. I changed some values and recompiled it but nothing changed ...
Later I realized that it was the CGI-Debug-Mode but I'm not sure if that isn't the same.
From /apache/src/modules/standard/mod_cgi.c
static int cgi_child(void *child_stuff, child_info *pinfo)
{
struct cgi_child_stuff *cld = (struct cgi_child_stuff *) child_stuff;
request_rec *r = cld->r;
char *argv0 = cld->argv0;
int child_pid;
#ifdef DEBUG_CGI
#ifdef OS2
/* Under OS/2 need to use device con. */
FILE *dbg = fopen("con", "w");
#else
FILE *dbg = fopen("/dev/tty", "w");
#endif
int i;
#endif
char **env;
RAISE_SIGSTOP(CGI_CHILD);
#ifdef DEBUG_CGI
fprintf(dbg, "Attempting to exec %s as %sCGI child (argv0 = %s)\n",
r->filename, cld->nph ? "NPH " : "", argv0);
#endif
ap_add_cgi_vars(r);
env = ap_create_environment(r->pool, r->subprocess_env);
#ifdef DEBUG_CGI
fprintf(dbg, "Environment: \n");
for (i = 0; env[i]; ++i)
fprintf(dbg, "'%s'\n", env[i]);
#endif
#ifndef WIN32
ap_chdir_file(r->filename);
#endif
if (!cld->debug)
ap_error_log2stderr(r->server);
/* Transumute outselves into the script.
* NB only ISINDEX scripts get decoded arguments.
*/
#ifdef TPF
return (0);
#else
ap_cleanup_for_exec();
child_pid = ap_call_exec(r, pinfo, argv0, env, 0);
#if defined(WIN32) || defined(OS2)
return (child_pid);
#else
/* Uh oh. Still here. Where's the kaboom? There was supposed to be an
* EARTH-shattering kaboom!
*
* Oh, well. Muddle through as best we can...
*
* Note that only stderr is available at this point, so don't pass in
* a server to aplog_error.
*/
ap_log_error(APLOG_MARK, APLOG_ERR, NULL, "exec of %s failed", r->filename);
exit(0);
/* NOT REACHED */
return (0);
#endif
#endif /* TPF */
}
Any C++ programmers in?
Please help!
Thanks again to both of you.
dmr.
Code that I author is neither elegant nor efficient. It is, however, functional. Once I get something that works, I'm generally satisfied with myself - I mean, if it works, that's good enough, right?
Originally posted by aknisely
Sorry, but I feel uncomfortable on CC with clothes on
__________________
The truth ... is out there!
-
Oct 1st, 2001, 10:24 AM
#16
Black Cat
Josh
Get these: Mozilla Opera OpenBSD
I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.
-
Oct 1st, 2001, 12:56 PM
#17
Thread Starter
Addicted Member
Josh, I saw you writing in the C and C++ Forum so it seems to me that you know what you're talking about...
I'd be very pleased if you can translate the second code into VB. I tried it, but I failed. I can rewrite simple C++ codes but that one...
Or is there somebody in the C and C++ Forum you know who has nothing to do at the moment and who I can ask for? Or should I just post there?
Thank a lot for your help!
Code that I author is neither elegant nor efficient. It is, however, functional. Once I get something that works, I'm generally satisfied with myself - I mean, if it works, that's good enough, right?
Originally posted by aknisely
Sorry, but I feel uncomfortable on CC with clothes on
__________________
The truth ... is out there!
-
Oct 1st, 2001, 01:55 PM
#18
Black Cat
Um, actually I'm still learning (always learning...), so converting that code to VB is still a little beyond me... ( I could probably get it if I stuggled with it for awhile).
Go ahead and ask on the C forum. There's some smart people there.
Josh
Get these: Mozilla Opera OpenBSD
I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.
-
Oct 1st, 2001, 03:15 PM
#19
Thread Starter
Addicted Member
That doesn't matter. I opened a thread in the C-Forum.
I have to express my gratitude to you.
Thanks a lot for your patience!
dmr.
Code that I author is neither elegant nor efficient. It is, however, functional. Once I get something that works, I'm generally satisfied with myself - I mean, if it works, that's good enough, right?
Originally posted by aknisely
Sorry, but I feel uncomfortable on CC with clothes on
__________________
The truth ... is out there!
-
Oct 1st, 2001, 03:32 PM
#20
Black Cat
Ok. I do have a simple app in VB that does the opposite of what you want -- runs as CGI under IIS. Some of the API declarations and such should be same. I'll post it tomorrow if you want it.
Josh
Get these: Mozilla Opera OpenBSD
I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.
-
Oct 1st, 2001, 03:34 PM
#21
Thread Starter
Addicted Member
Sounds really interesting.
Please post it!
Tia.
Code that I author is neither elegant nor efficient. It is, however, functional. Once I get something that works, I'm generally satisfied with myself - I mean, if it works, that's good enough, right?
Originally posted by aknisely
Sorry, but I feel uncomfortable on CC with clothes on
__________________
The truth ... is out there!
-
Oct 2nd, 2001, 10:52 AM
#22
Black Cat
This would go into a module, and set project startup to Sub Main. Enjoy!
VB Code:
Option Explicit
Private Const STD_ERROR_HANDLE As Long = -12&
Private Const STD_INPUT_HANDLE As Long = -10&
Private Const STD_OUTPUT_HANDLE As Long = -11&
Private Const GENERIC_WRITE As Long = &H40000000
Private Const FILE_SHARE_READ As Long = &H1&
Private Const OPEN_ALWAYS As Long = 4&
Private Const FILE_ATTRIBUTE_ARCHIVE As Long = &H20&
Private Const FILE_END As Long = 2&
Private Declare Function CloseHandle Lib "kernel32.dll" (ByVal hObject As Long) As Long
Private Declare Function WriteFile Lib "kernel32.dll" (ByVal hFile As Long, _
lpBuffer As Any, ByVal nNumberOfBytesToWrite As Long, _
lpNumberOfBytesWritten As Long, lpOverlapped As Any) As Long
Private Declare Function CreateFile Lib "kernel32.dll" Alias "CreateFileA" _
(ByVal lpFileName As String, ByVal dwDesiredAccess As Long, _
ByVal dwShareMode As Long, lpSecurityAttributes As Any, _
ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, _
ByVal hTemplateFile As Long) As Long
Public Declare Function SetFilePointer Lib "kernel32.dll" (ByVal hFile As Long, _
ByVal lDistanceToMove As Long, lpDistanceToMoveHigh As Long, _
ByVal dwMoveMethod As Long) As Long
Private Declare Function GetStdHandle Lib "kernel32" _
(ByVal nStdHandle As Long) As Long
Private Declare Function GetEnvironmentVariable Lib "kernel32" Alias "GetEnvironmentVariableA" _
(ByVal lpName As String, ByVal lpBuffer As String, ByVal nSize As Long) As Long
Private Declare Function AllocConsole Lib "kernel32" () As Long
Private Declare Function FreeConsole Lib "kernel32" () As Long
Public Sub Main()
Dim STDOUT As Long 'handle to standard output
Dim strHTTP As String 'data buffer for HTTP header output
Dim strBuffer As String 'data buffer for writing to the log file
Dim lngBytesWritten As Long 'the number of bytes that were written
Dim retval As Long 'API return value
Dim FILEOUT As Long 'handle to the file to log to
'CGI Variables
Dim strQueryString As String
Dim strRemoteAddr As String
Dim strHTTPUserAgent As String
'fill the buffers with nothing
strQueryString = Space$(256)
strRemoteAddr = strQueryString
strHTTPUserAgent = strQueryString
'get and store the CGI variables needed
retval = GetEnvironmentVariable("QUERY_STRING", strQueryString, 256)
strQueryString = Left$(strQueryString, retval)
retval = GetEnvironmentVariable("REMOTE_ADDR", strRemoteAddr, 256)
strRemoteAddr = Left$(strRemoteAddr, retval)
retval = GetEnvironmentVariable("HTTP_USER_AGENT", strHTTPUserAgent, 256)
strHTTPUserAgent = Left$(strHTTPUserAgent, retval)
strHTTP = "Location: ./win2000.gif" & vbCrLf & vbCrLf
'start the console
'retval = AllocConsole 'UNCOMMENT FOR IDE DEBUGGING
'get the handle to standard output
STDOUT = GetStdHandle(STD_OUTPUT_HANDLE)
'write the string to STDOUT, just like writing to a file
retval = WriteFile(STDOUT, ByVal strHTTP, Len(strHTTP), lngBytesWritten, ByVal 0&)
'close the handle to standard out
retval = CloseHandle(STDOUT)
'close the console
'retval = FreeConsole 'UNCOMMENT FOR IDE DEBUGGING
'open the file for writing
FILEOUT = CreateFile("C:\Inetpub\wwwroot\Test\image.log", GENERIC_WRITE, FILE_SHARE_READ, _
ByVal 0&, OPEN_ALWAYS, FILE_ATTRIBUTE_ARCHIVE, 0)
'if error
If FILEOUT = -1 Then Exit Sub
'fill the buffer
strBuffer = Now & ";" & strQueryString & ";" & strRemoteAddr & ";" & strHTTPUserAgent & vbCrLf
'move the file pointer to EOF
retval = SetFilePointer(FILEOUT, 0, 0, FILE_END)
'write the buffer to the file
retval = WriteFile(FILEOUT, ByVal strBuffer, Len(strBuffer), lngBytesWritten, ByVal 0&)
'close the handle to the file
retval = CloseHandle(FILEOUT)
End Sub
Josh
Get these: Mozilla Opera OpenBSD
I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.
-
Oct 4th, 2001, 04:34 PM
#23
Thread Starter
Addicted Member
Thanks Josh!
The code works great!
I haven't tried yet to rewrite it for my needs but I think I do it on weekend. 
Thanks for your patience!
Code that I author is neither elegant nor efficient. It is, however, functional. Once I get something that works, I'm generally satisfied with myself - I mean, if it works, that's good enough, right?
Originally posted by aknisely
Sorry, but I feel uncomfortable on CC with clothes on
__________________
The truth ... is out there!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|