Forum

cURL HTTP POST

Discuss programming topics for the various GPL'd game engine sources.

Moderator: InsideQC Admins

cURL HTTP POST

Postby Baker » Thu Dec 01, 2011 10:22 pm

I'm just stuffing this here. I know Spike has some of sort of MYSQL or SQLite thingy for FTE server.

But I'm kinda thinking centralized server database, not localhost.

And while this link and the code are PHP, it is PHP using cURL which is straightforward to put into C since cURL is basically cURL on whatever platform.

What I find most interesting about this specific example is the illustration of having PHP call a PHP web page and fill out a form.

Yes, yes this might be one of the most convoluted posts in the engine section in a way, but in a way it isn't because if I implement this idea out the server side will be rather LAMP-y anyway so the engine code will go hand-in-hand with PHP5 anyways (although the way PHP5 interacts with databases, it wouldn't be MYSQL-specific).

http://davidwalsh.name/execute-http-post-php-curl

Code: Select all
//extract data from the post
extract($_POST);

//set POST variables
$url = 'http://domain.com/get-post.php';
$fields = array(
            'lname'=>urlencode($last_name),
            'fname'=>urlencode($first_name),
            'title'=>urlencode($title),
            'company'=>urlencode($institution),
            'age'=>urlencode($age),
            'email'=>urlencode($email),
            'phone'=>urlencode($phone)
        );

//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string,'&');

//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);

//execute post
$result = curl_exec($ch);

//close connection
curl_close($ch);
The night is young. How else can I annoy the world before sunsrise? 8) Inquisitive minds want to know ! And if they don't -- well like that ever has stopped me before ..
User avatar
Baker
 
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Re: cURL HTTP POST

Postby Jukki » Fri Dec 02, 2011 4:51 am

ive done this for my game, best thing using the curl instead of mysql connector is that curl has ben portedto many devices (including psp <3)
Jukki
 
Posts: 214
Joined: Wed Apr 07, 2010 4:59 am

Re: cURL HTTP POST

Postby revelator » Fri Dec 02, 2011 10:53 am

Many usefull gnu utilities for windows aye :)
Productivity is a state of mind.
User avatar
revelator
 
Posts: 2567
Joined: Thu Jan 24, 2008 12:04 pm
Location: inside tha debugger

Re: cURL HTTP POST

Postby Baker » Fri Dec 02, 2011 3:06 pm

reckless wrote:Many usefull gnu utilities for windows aye :)


Eh? Reckless, ya lost me there??

[In truth, I've spend maybe only 10 minutes on Windows in the last 2 weeks. I've largely abandoned Windows. I'll still boot up my Windows machine to compile Windows versions of Quake engine stuff, but my personal in-process Quake engine work is platform transparent so I don't need Windows for engine coding.


anti-Windows rant follows ... hehehe :P


Over the last 3 years, I probably used my OS X machine more than my Windows machines except for engine coding. And in this last month I've basically permanently switched away from Windows and aside from liking Visual Studio a bit more than XCode (and Microsoft has the best development documentation on the planet), I don't miss Windows.

I think the only strength of Windows is Visual Studio. Windows is just a terribly legacy operating system with a ton of bandages to smooth over things, the future is going to be more "cloud" and Web App/Web Services oriented.

What I like about OS X is that essentially you do virtually anything you'd do on Linux, it is built-in and unlike Linux ... it works and it works the first time. So you can PHP or SQL or Terminal what not ... the desktop GUI is incredible ... you mount stuff ... people can't install stuff on your machine without your consent ... you don't need to be paranoid about viruses and trojans.

It takes some work to find equivalent applications ... like I obviously can't use WinMerge but KDiff3 is about the same deal. No Paintshop Pro (I have no intention of ever buying Photoshop and likewise I do not believe in stealing, Gimp is "ok" but it is not laid out well) but Pixen is pretty good open source raster graphics editor.)

I still enjoy coding on Windows and for Windows, but I don't see Windows really having a "meaningful" future [I could be wrong] in what will eventually be a Web Apps world and I think one example of how bad of a platform Windows is .... the successful of the Xbox. People basically prefer console gaming because Windows is a maintenance crapfest and no one wants to deal with that, and games are great example of that.

And Windows can never be fixed because too many legacy business applications depend on its bad design structure.

Sure Windows will carry on for decades for that reason alone, but seriously ... and MS Office? When do people *really* print anything these days and if they do you can use Google docs. Open Office has a spreadsheet app.

What I like about OS X is that you get about the same advantages of Linux under the hood, no Windows liabilities or maintenance nightmares and is it like Linux except the part with Linux where you have to continually research oddities and play with text files to get stuff to work.

/Yeah, yeah unexpected supertangent maximus :mrgreen:
The night is young. How else can I annoy the world before sunsrise? 8) Inquisitive minds want to know ! And if they don't -- well like that ever has stopped me before ..
User avatar
Baker
 
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Re: cURL HTTP POST

Postby revelator » Fri Dec 02, 2011 3:24 pm

Hehe no problem :) i was not aware you coded for mac so i assumed you used the curl port.
Windows will probably newer go away to much cash invested from said companies ;)
but i suspect linux future to be quite bright as a free alternative for new companies (many here in denmark use ubuntu).
i do have a hard time convincing the government though due to the above cash problem (seems ms made some clausul that makes it unbenefitfull to change :S something about the licenses being adoptable to newer systems).
Productivity is a state of mind.
User avatar
revelator
 
Posts: 2567
Joined: Thu Jan 24, 2008 12:04 pm
Location: inside tha debugger

Re: cURL HTTP POST

Postby Baker » Fri Dec 02, 2011 3:59 pm

reckless wrote:Hehe no problem :) i was not aware you coded for mac so i assumed you used the curl port.


Hehe. :D Well, see if I was looking for a Windows only solution I probably wouldn't use cURL. In Windows, there is some simple API function that eludes me at the moment where I could skip all cURL stuff. But utilizing cURL I can expect it run on at a minimum all 3 desktop platforms and anything else cURL is ported to.

I'm really thinking server here, so I said LAMP in the first post.

/ I've had an OS X version of ProQuake for 3 years, converted Kurok to SDL for OS X earlier in the year ...

And when Metlslime released FitzQuake 0.85 in 2009, Spirit got all depressed when he got told that FitzQuake 0.85 SDL would be like a year away, so I spent 6 hours merging the FitzQuake 0.80 SDL and FitzQuake 0.85 together into an unofficial FitzQuake 0.85 SDL so he could it on Linux (and I'd get to use it on my Mac) [then the Quakespasm took that engine and finessed it up really nice, heheh].

Windows will probably newer go away to much cash invested from said companies ;)


That is likely true. If you have a system that works that a lot of time was invested in, you'll keep using that forever or until it breaks.

Then again, things do end up changing over time. If you go back 5 years ago, no one ever saw Android coming. If you go back 10 years ago, few people knew of Google. And 20 years ago, WordPerfect and Lotus 1-2-3 were the popular wordprocessor and spreadsheet software.

but i suspect linux future to be quite bright as a free alternative for new companies (many here in denmark use ubuntu).


Linux has a much higher adoption rate in Europe (20% ?). I have always rooted for Linux, but I've been waiting 8 years and I like Ubuntu is leaps and bounds better, I don't have the time or interest to collect all drivers and figure out all the little nickpicks that never work without configuration.

But I have given up on the idea that Linux will ever be easy to setup, then again it is not like I ever bought a machine with Linux preinstalled (not that they really sell those in the US, but I am saying that installing Ubuntu and setting it up by nature really shouldn't be expected to match a manufacturer preconfiguration of another OS, still there are other things that annoy me about Linux desktops ...)

I still love Linux as a server, obviously.

i do have a hard time convincing the government though due to the above cash problem (seems ms made some clausul that makes it unbenefitfull to change :S something about the licenses being adoptable to newer systems).


There are switching costs involved in change, so that is always a reason to maintain what you've got.
The night is young. How else can I annoy the world before sunsrise? 8) Inquisitive minds want to know ! And if they don't -- well like that ever has stopped me before ..
User avatar
Baker
 
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Re: cURL HTTP POST

Postby revelator » Fri Dec 02, 2011 5:08 pm

Well atleast with curl we dont run ito any licensing issues etc ;). Also i find it works like a charm in the few projects i been using it in so im quite inclined to stick with what i know.

And yep thats pretty much the line they fed me when i asked why they didnt use linux xD
Productivity is a state of mind.
User avatar
revelator
 
Posts: 2567
Joined: Thu Jan 24, 2008 12:04 pm
Location: inside tha debugger

Re: cURL HTTP POST

Postby revelator » Fri Dec 02, 2011 5:12 pm

Btw ubuntu has evolved quite a bit migth be easier finding and installing drivers today :)
else i can put in a good word for opensuse allthough some might not like the gadget type UI of the KDE version its pretty easy to get around in.
Productivity is a state of mind.
User avatar
revelator
 
Posts: 2567
Joined: Thu Jan 24, 2008 12:04 pm
Location: inside tha debugger

Re: cURL HTTP POST

Postby Baker » Tue Dec 06, 2011 3:56 am

reckless wrote:Btw ubuntu has evolved quite a bit migth be easier finding and installing drivers today :)
else i can put in a good word for opensuse allthough some might not like the gadget type UI of the KDE version its pretty easy to get around in.


I've used Ubuntu within the last 10 months. It isn't bad, but I find the cascading dependencies and annoyances with the different sound systems and such. Plus the configuration hassles annoying. And the GUI wanting. :( OS X handles all of these things very nicely without loading up Terminal. Forcing the use of the command line to perform certain tasks just is not going to fly in 2011 ... not for the mainstream.

I will say, I am looking hard and long at Qt ... as an example MH commented about the D3 source not compiling with MSVC Express 2010 due to MFC. I think Quake needs a decent Open Source map editor and in my opinion QER will likely be that editor.

I will say that I do not believe in operating system dependent applications, nor for Windows and not for OS X. I just do not like platform lock. And in 2011, I view platform lock as n00b and naive (except in special cases like DirectQ where using a specific rendering API, for instance, is inherently a platform lock.).

I would say that the only thing I miss on OS X is WinMerge, but ... well ... I'm not really missing it :D

(The next version of WinMerge ... dubbed WinMerge 3 will be using the Qt library.)

Image
The night is young. How else can I annoy the world before sunsrise? 8) Inquisitive minds want to know ! And if they don't -- well like that ever has stopped me before ..
User avatar
Baker
 
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am


Return to Engine Programming

Who is online

Users browsing this forum: No registered users and 1 guest