Advertisement

php and c++ working together

Started by January 25, 2003 06:25 AM
10 comments, last by iamwithstupid 21 years, 9 months ago
hi just wondering what is the best way to make an executable, which opens up the default web browser and passes variables to a php script on my server. basic example: the user types in their name, the program stores it, opens up the default web browser and passes the variable to the php script and displays their name or takes a certain action. I figured i could use ShellExecute(NULL, "open", "http://www.mywebsite.com/executable.php?ID=1",NULL, NULL,SW_SHOWNORMAL); but knowing more c++ than php, i don't know how to read the variables. any ideas? thanks in advance jack [edited by - iamwithstupid on January 25, 2003 7:26:56 AM]
are you asking how to access the command line variables in php? if so, they will have already been defined, so just access them normally, e.g., " if ( $ID != 0 ) { " .
Advertisement
Yeh that is what i want to do, but it just doesn't seem to be working!

    // the c++ file #include <windows.h>int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd){	ShellExecute(NULL, "open", "http://www.mywebsite.com/executable.php?ID=1",NULL, NULL,SW_SHOWNORMAL);return 0;} 

and here is the php script

           // test php file on the serverecho "Hello, this is a test area, which will hopefully do something exciting eventually!!!";if ($ID != 1) {echo "it worked";}else {echo "Not it didn't work";}?>   


As you can see ID is equal to 1 but it still says it works, it doesn't change unless i actually define id as something inside the actual php script.

Is there soemthing wrong with the way i am trying to pass the variable in the address?

thanks again
jack


[edited by - iamwithstupid on January 25, 2003 10:05:38 AM]
the problem could be in the ShellExecute call. you might try separating the params from the file. in other words,

  ShellExecute(NULL, "open", "http://www.mywebsite.com/executable.php", "?ID=1", NULL, SW_SHOWNORMAL);  
good idea ap, but it still doesn''t work!

any other ideas?

thanks
jack
The problem is with your PHP script,

You first need to set your $ID variable with the value from the address.

$ID = $_GET["ID"];

should do the trick,

Have Fun
Advertisement
do you have access to the server''s log files? the request should be in there, along with the params, if any. this would at least tell you whether the problem is on the client side or the server side (possibly; i''m assuming normal browsing works. )

i''d also suggest trying this with an explicit execution of your browser, with the entire address and params as the param string for ShellExecute.
LowCalorieSoftDrink, i thought the web server''s php plugin did that? i guess i should have asked instead of assuming.
Yes
thanks LowCalorieSoftDrink and ap, it has finally worked
$ID = $_GET["ID"];, did the trick.

thanks alot
jack
When a page request is sent to the server, any request variables, i.e. anything after the & in the address, is parsed into an array, i.e. $_GET["name of var"].

Its the same with post request variables, but these are stored in $_POST["var name"].

Anyway im gunna shut up now.

This topic is closed to new replies.

Advertisement