我正在尝试使用付款处理器设置API.以下是他们提供给我的代码.我想要的$ result变量中有一些信息,我不明白的是什么类型的变量是'$ result'以及如何从中获取某些数据.打印$ result显示"交易ID为:xxxx状态为ACCEPTED".我基本上想要的是只获取事务ID并将其存储在变量中.
foreach($_POST as $k=>$v) $$k=urldecode($v);
$urladdress = "https://example.com/accapi/process.php";
$api_id = "dddd";
$api_pwd = "yyyyy";
$api_pwd = md5($api_pwd.'s+E_a*');
$data = "user=".$user. "&testmode=".$testmode."&api_id=".$api_id. "&api_pwd=".$api_pwd."&amount=".$amount."&paycurrency=".$currency."&comments=".$comments."&fee=".$fee."&udf1=".$udf1;
// Call STP API
$ch = curl_init(); curl_setopt($ch, CURLOPT_URL,"$urladdress");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0); //use this to suppress output
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);// tell cURL to graciously accept an SSL certificate
$result = curl_exec ($ch) or die(curl_error($ch));
echo $result;
echo curl_error($ch);
curl_close ($ch);
Run Code Online (Sandbox Code Playgroud)
谢谢您的帮助
解决方案:经过几个小时的搜索后,当我访问我的网站而没有添加"www"时,似乎出现了这个问题.在域名之前.所以实际发生的事情是,我正在使用example.com/login.php登录设置会话,我的成员控件无法识别,因此它将我重定向回www.example.com/login.php,我登录一切正常.
当我从www.example.com/login.php(使用www.)登录时,它会从第一次尝试正确登录.
所以我添加了一个代码,以确保我在URL中始终有www:
if ($_SERVER['HTTP_HOST'] == "example.com")
{
$url = "http://www." . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
header("Location: $url");
}
Run Code Online (Sandbox Code Playgroud)
一切都很好.希望它可以帮助某人.
所以,我已经建立了3个以上的网站,并且都有相同的问题,我不知道为什么,我必须登录两次,直到我登录了...(直到会话变量设置).非常感谢帮助,一直试图解决这个问题并寻找解决方案很长一段时间......
session_start();
if ((isset($_SESSION['UserName']))&&(isset($_SESSION['LastActivity'])))
{
header ('Location: http://www.example.com/Account.php');
}
if (isset($_POST['username']))
{
mysql_connect("localhost","DBuser","pass") or
die ("could not connect to mysql");
mysql_select_db("DBNAME") or die ("no database");
$inputUserName = $_POST['username'];
$inputPass = $_POST['password'];
$datausername = mysql_real_escape_string($inputUserName);
$password=md5($inputPass);
$sqlCommand = "SELECT * FROM Members
WHERE UserName='$datausername' AND
Password='$password'";
$result = mysql_query($sqlCommand);
if (mysql_num_rows($result) > 0)
{
$_SESSION['UserName'] = $datausername;
$_SESSION['LastActivity']= time();
sleep(2);
$LoginDate = …Run Code Online (Sandbox Code Playgroud)