2017-05-02 25 views
0

我需要脚本来打开执行查询的php页面。特别是我必须做一个登录/注册。我已经有查询和数据库工作来做到这一点(我有一个工作登录/我的网站上注册)。 我想直接使用c + +连接到服务器,并从程序发送查询,但我听说这是由于安全(特别是我不能连接到服务器,除非我直接从网站做它)的dicuraged。 所以我在互联网上发现,做到这一点的最佳方式是写连接到服务器和.php页面上的查询,而不是由C++程序调用,并在POST中传递变量(用户名和密码)登录或注册。 我可以编写php页面,但我不知道如何制作该程序。
基本上,在伪代码,我想这样做使用C++打开一个PHP页面(执行查询)

//Things i already know how to do 
- read username from console 
- read password from console 
- read if the user wants to login or register 
//Things i don't know how to do 
- send username, password (and if the user wants to login or register) to a php page that can execute the right queries and connect to the db 
- perform all the checks on the username (not duplicated etc) 

通过了解如何打开PHP页面我也可以做其他的事情,我很intrested像创建日志后,由用户所采取的行动连接(其实在登陆后,您可以播放在DirectX一个小游戏后,这样我就可以上传像比分或播放等的时间) 非常感谢

+0

您可能想要做的是使用C++进行HTTP请求,请参阅:http://stackoverflow.com/questions/1011339/how-do-you-make-a-http-request-with-c。 'libcurl'是一个完整的解决方案。 –

+0

Igor ok谢谢,我想我可以找到这个有用的 – Emanuele

回答

0

你可以窥视CURL library for C/C++

正常控制台操作是微不足道的。当您从用户处获得详细信息时,请使用curl向服务器发起[登录]请求。