Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 261
  • Last Modified:

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
0
InteractiveMind
Asked:
InteractiveMind
  • 5
  • 3
2 Solutions
 
InteractiveMindAuthor Commented:
winsock, right?
0
 
trigger-happyCommented:
I'd recommend using a library like libcurl for posting data: http://www.curl.haxx.se

--trigger-happy
0
 
InteractiveMindAuthor Commented:
Any examples of use?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
trigger-happyCommented:
There are tutorials on the site for the basic usage of curl, but if you want a sample on how to post data:

int VFinder::Login(){
        m_page.clear();
        string field;
        string battle("http://www.kingsofchaos.com/battlefield.php");
        if(!m_login){
                if(m_srank>0){
                        ostringstream converter;
                        converter << m_srank;
                        battle.append("?start=");
                        battle.append(converter.str());
                }
                field.assign("username=&pword=&usrname=");
                field.append(m_user+"&uemail="+m_email+"&peeword="+m_pword+"&hash=");

                curl_easy_setopt(m_handle, CURLOPT_URL, "http://www.kingsofchaos.com/login.php");
                curl_easy_setopt(m_handle, CURLOPT_WRITEFUNCTION, VFinder::store);
                curl_easy_setopt(m_handle, CURLOPT_COOKIEJAR, "cookie.txt");
                curl_easy_setopt(m_handle, CURLOPT_POST, true);
                curl_easy_setopt(m_handle, CURLOPT_POSTFIELDS, field.c_str());
                curl_easy_setopt(m_handle, CURLOPT_POSTFIELDSIZE, field.size());
                curl_easy_perform(m_handle);
                m_login = true;
        }

        curl_easy_setopt(m_handle, CURLOPT_POST, false);
        curl_easy_setopt(m_handle, CURLOPT_URL, battle.c_str());
        curl_easy_perform(m_handle);
        return 0;
}

Feeling lazy right now :P so i just copy pasted code from my application that i made

--trigger-happy
0
 
InteractiveMindAuthor Commented:
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
0
 
InteractiveMindAuthor Commented:
Hm, bloody hell. I didn't realise... everything within the 'Include' folder within the Libcurl download are mere header files!
0
 
InteractiveMindAuthor Commented:
lol <btw, I meant that in a funny and sarcastic manner; not offensive>
0
 
trigger-happyCommented:
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
0
 
puranik_pCommented:
You can use HTTP functionality.
i.e. u can define your HTTP handlers. e.g.

Add #include <afxinet.h>    // MFC Internet support

HINTERNET     m_hInternetSession;
HINTERNET     m_hHttpConnection;
 HINTERNET     m_hHttpFile;

//Open internet session.
ASSERT(m_hInternetSession == NULL);
m_hInternetSession = ::InternetOpen(AfxGetAppName(), INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);  

You can visit the link to  have brief idea of rest of the functionality:
http://www.dotnetheaven.com/Uploadfile/mahesh/commonWinInetAPI05242005064319AM/commonWinInetAPI.aspx?ArticleID=6335300f-3eda-4199-9888-a71fc138fb73 
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now