Link to home
Start Free TrialLog in
Avatar of InteractiveMind
InteractiveMindFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Connect to PHP website, and pass params

I have a string, which I'd like to pass to a PHP webpage, in the form of either POST or GET data (whichever one is easiest).

e.g.

   http://www.mydomain.com/myscript.php?getVar=mystr

Or whatever..

So that my PHP script can then parse the data, and store it on my web server.

Any ideas?

Thanks
Avatar of InteractiveMind
InteractiveMind
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

winsock, right?
I'd recommend using a library like libcurl for posting data: http://www.curl.haxx.se

--trigger-happy
Any examples of use?
ASKER CERTIFIED SOLUTION
Avatar of trigger-happy
trigger-happy
Flag of Philippines image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Right, I found a POST example:


#include <stdio.h>
#include <curl/curl.h>

int main(void)
{
  CURL *curl;
  CURLcode res;

  char *postthis="moo mooo moo moo";

  curl = curl_easy_init();
  if(curl) {
    curl_easy_setopt(curl, CURLOPT_URL, "http://mydomain.com/page.php");
    curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postthis);

    /* if we don't provide POSTFIELDSIZE, libcurl will strlen() by
       itself */
    curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, strlen(postthis));

    res = curl_easy_perform(curl);

    /* always cleanup */
    curl_easy_cleanup(curl);
  }
  return 0;
}


And I've copied the curl/.. lib into Dev-C++'s include folder, and have pointed my the directories within my Compiler Options to it, but am getting linker errors:


Compiler: Default compiler
Executing  g++.exe...
g++.exe "C:\Documents and Settings\rob\Desktop\KL\post.cpp" -o "C:\Documents and Settings\rob\Desktop\KL\post.exe"    -I"C:\Program Files\Dev-Cpp\include\c++\3.3.1"  -I"C:\Program Files\Dev-Cpp\include\c++\3.3.1\mingw32"  -I"C:\Program Files\Dev-Cpp\include\c++\3.3.1\backward"  -I"C:\Program Files\Dev-Cpp\lib\gcc-lib\mingw32\3.3.1\include"  -I"C:\Program Files\Dev-Cpp\include"  -I"C:\Program Files\Java\jdk1.5.0_01\include"  -I"C:\Program Files\Java\jdk1.5.0_01\include\win32"  -I"C:\Program Files\Dev-Cpp\include\curl"   -L"C:\Program Files\Dev-Cpp\lib" -L"C:\Program Files\Java\jdk1.5.0_01\include" -L"C:\Program Files\Java\jdk1.5.0_01\include\win32" -L"C:\Documents and Settings\rob\Desktop\CpuUsage_src" -L"C:\masm32\lib" -L"C:\Program Files\Dev-Cpp\include\curl"

C:\DOCUME~1\rob\LOCALS~1\Temp/ccCWbaaa.o(.text+0x54):post.cpp: undefined reference to `_imp__curl_easy_init'
C:\DOCUME~1\rob\LOCALS~1\Temp/ccCWbaaa.o(.text+0x7a):post.cpp: undefined reference to `_imp__curl_easy_setopt'
C:\DOCUME~1\rob\LOCALS~1\Temp/ccCWbaaa.o(.text+0x96):post.cpp: undefined reference to `_imp__curl_easy_setopt'
C:\DOCUME~1\rob\LOCALS~1\Temp/ccCWbaaa.o(.text+0xba):post.cpp: undefined reference to `_imp__curl_easy_setopt'
C:\DOCUME~1\rob\LOCALS~1\Temp/ccCWbaaa.o(.text+0xc7):post.cpp: undefined reference to `_imp__curl_easy_perform'
C:\DOCUME~1\rob\LOCALS~1\Temp/ccCWbaaa.o(.text+0xd7):post.cpp: undefined reference to `_imp__curl_easy_cleanup'

Execution terminated
Hm, bloody hell. I didn't realise... everything within the 'Include' folder within the Libcurl download are mere header files!
lol <btw, I meant that in a funny and sarcastic manner; not offensive>
I'm not sure what IDE you're using but you have to find a way to make it link to the curl library (you have to add "-lcurl" there).

--trigger-happy
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial