[英]Using the login Details via Application
我有一个CURL(C ++)发送给我的用户并传递给remauth.php文件,所以我认为我在remuth.php上做错了什么(因为我是php的基本用户,并且我的程序无法运行,因为未通过身份验证。)我使用通过应用程序登录。
我的CURL:
bool Auth_PerformSessionLogin(const char* username, const char* password)
{
curl_global_init(CURL_GLOBAL_ALL);
CURL* curl = curl_easy_init();
if (curl)
{
char url[255];
_snprintf(url, sizeof(url), "http://%s/remauth.php", "SITEADDRESS.com");
char buf[8192] = {0};
char postBuf[8192];
_snprintf(postBuf, sizeof(postBuf), "%s&&%s", username, password);
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, AuthDataReceived);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)&buf);
curl_easy_setopt(curl, CURLOPT_USERAGENT, "IW4M");
curl_easy_setopt(curl, CURLOPT_FAILONERROR, true);
curl_easy_setopt(curl, CURLOPT_POST, 1);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postBuf);
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, -1);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false);
CURLcode code = curl_easy_perform(curl);
curl_easy_cleanup(curl);
curl_global_cleanup();
if (code == CURLE_OK)
{
return Auth_ParseResultBuffer(buf);
}
else
{
Auth_Error(va("Could not reach the SITEADDRESS.comt server. Error code from CURL: %x.", code));
}
return false;
}
curl_global_cleanup();
return false;
}
和我的remauth.php:
<?php
ob_start();
$host=""; // Host name
$dbusername=""; // Mysql username
$dbpassword=""; // Mysql password
$db_name=""; // Database name
$tbl_name=""; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$dbusername", "$dbpassword") or die(mysql_error());
mysql_select_db("$db_name") or die(mysql_error());
// Define $username and $password
//$username=$username;
//$password=md5($_POST['password']);
//$password=$password;
$username=$_POST['username'];
$password=$_POST['password'];
//$post_item[]='action='.$_POST['submit'];
// To protect MySQL injection (more detail about MySQL injection)
$username = stripslashes($username);
$password = stripslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
$sql="SELECT * FROM $tbl_name WHERE username='$username'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $username and $password, table row must be 1 row
if($count==1){
$row = mysql_fetch_assoc($result);
if (md5(md5($row['salt']).md5($password)) == $row['password']){
session_register("username");
session_register("password");
echo "#";
return true;
}
else {
echo "o";
return false;
}
}
else{
echo "o";
return false;
}
ob_end_flush();
?>
///////////////////////////////////
出现卷曲错误吗? 是否完全执行了php脚本?
您是否只是为了发布而添加了SITEADDRESS,还是这是编译器应替换为您要连接的网站的定义? 如果是第二个,它将在“”内不起作用,因为它将被视为文字并且不会被替换。
同样,您两次调用curl_global_cleanup(),一次在if子句内,一次在函数末尾。 您只能调用一次。 您的函数可能多次调用了吗? 然后,您应该将全局init和clean移到其他位置,因为curl假定它们在程序中仅被调用一次。 这不会解决您的实际问题,但这是一个好习惯。
//To get the posted data without the fieldnames use:
$data = file_get_contents('php://input');
//And then split the data by '&&'
$new_data = explode('&&', $data);
$username = $new_data[0];
$password = $new_data[1];
// more code...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.