PDA

View Full Version : ارسال پارامتر به یک صفحه PHP با زبان برنامه نوسی C++‎‎‎‎



omidd1315
سه شنبه 01 اردیبهشت 1394, 21:08 عصر
با سلام
من می خوام که با استفاده از زبان برنامه نویسی سی پلاس یه سری داده به یک صفحه php بفرستم با متد GEt مثلا
آدرس صفحه وب و دادهام به صورت زیر تعریف می شوند.


www.mysite.com/fun.php?username=admin&password=12345


حالا مثلا کد های اون صفحه پی اچ پی به صورت زیر باشه


<?php
$username=$_GET['username']

$password=$_GET['passworde']
?>


در واقع می خوام پارامترهایی که به این صفحه داده می شه در یک برنامه سی پلاس پلاس مقدار دهی بشه.
فقط نمی خوام که مرورگر سیستم بالا بیاد بره اون صفحه بلکه می خوام اتوماتیک این کار انجام بشه.
توی نت گشتم ولی از کداشون سر در نیوردم.
اگر کسی یه مثال کوچیک و جم و جور برام بزنه ممنونش میشم.
با تشکر فراوان

rahnema1
سه شنبه 01 اردیبهشت 1394, 23:10 عصر
سلام
میتونید از کتابخانه curl استفاده کنید
این هم عین مثال خود کتابخونه:

//Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
#include <stdio.h>
#include <curl/curl.h>

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

/* In windows, this will init the winsock stuff */
curl_global_init(CURL_GLOBAL_ALL);

/* get a curl handle */
curl = curl_easy_init();
if(curl) {
/* First set the URL that is about to receive our POST. This URL can
just as well be a https:// URL if that is what should receive the
data. */
curl_easy_setopt(curl, CURLOPT_URL, "http://postit.example.com/moo.cgi");
/* Now specify the POST data */
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "name=daniel&project=curl");

/* Perform the request, res will get the return code */
res = curl_easy_perform(curl);
/* Check for errors */
if(res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));

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

negative60
سه شنبه 01 اردیبهشت 1394, 23:24 عصر
تو ويندوز ميتونيد از توابع API کتاب خونه WinInet استفاده کنيد

#include <iostream>
#include <string.h>
#include <stdio.h>
#include <Windows.h>
#include <WinInet.h>


#pragma comment(lib, "wininet.lib")
using namespace std;


string OpenURL(const char *Url)
{
string strOut;
HINTERNET hSession = NULL;
HINTERNET hFile = NULL;
DWORD dwBytesRead = 0;


hSession = InternetOpenA("Mozilla/5.0", 1, NULL, NULL, 0);
if(!hSession)
{
return "";
}


hFile = InternetOpenUrlA(hSession, Url, NULL, NULL, INTERNET_FLAG_RELOAD | INTERNET_FLAG_DONT_CACHE, NULL);
if(!hFile)
{
//can't connect to host Url
InternetCloseHandle(hSession);
return "";
}


do {
char buffer[4000];
InternetReadFile(hFile, (LPVOID)buffer, sizeof(buffer), &dwBytesRead);
strOut.append(buffer, dwBytesRead);
} while (dwBytesRead);


InternetCloseHandle(hFile);
InternetCloseHandle(hSession);


return strOut;


}




void main()
{
string source = OpenURL("http://mysite.com/fun.php?username=admin&password=12345");


system("pause");


}

omidd1315
چهارشنبه 02 اردیبهشت 1394, 13:17 عصر
خیلی ممنون دوستان لطف بزرگی کردین:قلب:

JustCompiler
پنج شنبه 20 اسفند 1394, 12:00 عصر
سلام
نمیخواستم تایپیک جدید الکی ایجاد کنم
و چون کدشم مربوط به این تایپیک بود همینجا میگم.

یک مشکلی در curl دارم
کد :

#include <urlmon.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <wininet.h>
#include <iomanip>
#include <windows.h>
#include <fstream>
#include <sstream>
#include <curl/curl.h>
#include <stdio.h>
#include <stdlib.h>
#include <curl/curl.h>
#include <curl/easy.h>
#include <WinInet.h>

#pragma comment(lib, "wininet.lib")
using namespace std;

int main()
{
string OpenURL(std::string);
cout << OpenURL("http://www.google.com/");
getchar();
return 0;
}
string OpenURL(const char *Url)
{
string strOut;
HINTERNET hSession = NULL;
HINTERNET hFile = NULL;
DWORD dwBytesRead = 0;


hSession = InternetOpenA("Mozilla/5.0", 1, NULL, NULL, 0);
if (!hSession)
{
return "";
}


hFile = InternetOpenUrlA(hSession, Url, NULL, NULL, INTERNET_FLAG_RELOAD | INTERNET_FLAG_DONT_CACHE, NULL);
if (!hFile)
{
//can't connect to host Url
InternetCloseHandle(hSession);
return "";
}


do {
char buffer[4000];
InternetReadFile(hFile, (LPVOID)buffer, sizeof(buffer), &dwBytesRead);
strOut.append(buffer, dwBytesRead);
} while (dwBytesRead);

InternetCloseHandle(hFile);
InternetCloseHandle(hSession);
return strOut;
}


کد رو از لینک:
http://barnamenevis.org/showthread.php?492682-%D8%A7%D8%B1%D8%B3%D8%A7%D9%84-%D9%BE%D8%A7%D8%B1%D8%A7%D9%85%D8%AA%D8%B1-%D8%A8%D9%87-%DB%8C%DA%A9-%D8%B5%D9%81%D8%AD%D9%87-PHP-%D8%A8%D8%A7-%D8%B2%D8%A8%D8%A7%D9%86-%D8%A8%D8%B1%D9%86%D8%A7%D9%85%D9%87-%D9%86%D9%88%D8%B3%DB%8C-C-%E2%80%8E%E2%80%8E%E2%80%8E%E2%80%8E&highlight=curl+cpp
کمک گرفتم.

139549

ZAHRA V A
دوشنبه 08 شهریور 1395, 12:50 عصر
من درمورد این توابع سوال دارم.
InternetOpenA
InternetOpenurlA
پارامتر هاش چیه؟
توی این مثال کدوم متغیر ها به صفحه php ارسال شده؟
من با wampserver کارمیکنم. میتونم این کدو براش استفاده کنم؟