나는 for 루프를 통해 세션 배열에서 정보를 얻기위한 메소드를 사용하는 iam 클래스를 가지고 있습니다. 각 방법의 루프가 사용됩니다. 1. 총 항목 수를 계산합니다. 2. 총 가격을 더할 수 있지만 둘 다 반환하지는 않습니다. 메신저 총 금액을 사용하여 IPN에서 mc_gross 게시 된 값에 대해 그것을 확인하고 값이 동일하다면 나는 그것이 확인 된대로 데이터베이스에 판매를 위탁 할 계획입니다. 메신저가 총 가격을 얻으려고하는 방법은 0.00이 나에게 돌아왔다. 나는 여기에 구문이 틀린 것 같아요. 어떻게 든 여기에 구매를위한 클래스입니다. 두 가지 방법으로 문제가있는 iam은 gettotalcost()와 gettotalitems()가 내 클래스입니다.
<?php
class purchase {
private $itemnames; // from session array
private $amountofitems; // from session array
private $itemcost; //session array
private $saleid; //posted transaction id value to be used in sale and sale item tables
private $orderdate; //get current date time to be entered as datetime in sale table
private $lastname; //posted from ipn
private $firstname; //posted from ipn
private $emailadd; //uses sessionarray value
public function __construct($saleid,$firstname,$lastname)
{
$this->itemnames = $_SESSION['itemnames'];
$this->amountofitems =$_SESSION['quantity'];
$this->itemcost =$_SESSION['price'];
$this->saleid = $saleid;
$this->firstname = $firstname;
$this->lastname = $lastname;
$this->emailadd = $SESSION['username'];
mail($myemail, "session vardump ", echo var_dump($_SESSION), "From: [email protected]");
mail($myemail, "session vardump ",count($_SESSION['itemnames']) , "From: [email protected]");
}
public function commit()
{
$databaseinst = database::getinstance();
$databaseinst->connect();
$numrows = $databaseinst->querydb($query);
//to be completed
}
public function gettotalitems()
{
$numitems;
$i;
for($i=0; $i < count($this->amountofitems);$i++)
{
$numitems += (int) $this->amountofitems[$i];
}
return $numitems;
}
public function gettotalcost()
{
$totalcost;
$i;
for($i=0; $i < count($this->amountofitems);$i++)
{
$numitems = (int) $this->amountofitems[$i];
$costofitem =doubleval($this->itemcost [$i]);
$totalcost += $numitems * $costofitem;
}
return $totalcost;
}
}
?>
여기는 내가 클래스의 인스턴스를 만들고 사용하려고하는 곳입니다.
include ("purchase.php");
$purchase = new purchase($_POST['txn_id'],$_POST['first_name'],$_POST['last_name']);
$fullamount = $purchase->gettotalcost();
$fullAmount = number_format($fullAmount, 2);
$grossAmount = $_POST['mc_gross'];
if ($fullAmount != $grossAmount) {
$message = "Possible Price Jack attempt! the amount the customer payed is : " . $grossAmount .
" which is not equal to the full amount. the price of the products combined is " . $fullAmount. "
the transaction number for which is " . $_POST['txn_id'] . "\n\n\n$req";
mail("XXXXXXXXXXXX", "Price Jack attempt ", $message, "From: [email protected]");
exit(); // exit
}
미리 감사드립니다.
ive도이 줄을 내 생성자에 추가했습니다. 메일은 vardump에 아무것도 없다고 반환합니다.
mail($myemailaddress, "session vardump ", var_dump($_SESSION), "From: [email protected]");
도
으로 session_start 추가();
생성자 위쪽에 있고 작동하지 않습니다! 도움이 괜찮아요 내가 gotr vardump 별도의 PHP 페이지에 인쇄하고 나에게 이것을 준다.
(9) {[ "token"] => 문자열 (32) "964885a70512d21933d139663a8fe48a"[ "ID"] => 문자열 (19) "XXXXXXXX"[ "username"] => 문자열 (19) "XXXXXX "" "" "" "" "" "" ""= "문자열"(" "케이프 클리어 아일랜드 : 그 사람과 풍경"[1] => 문자열 (30) "Naomh Ciaran : 순례자 섬 주민"[2] => string (35) "array [3] {0} (1) "1"[2] => 문자열 (1) => 문자열 (1) (5) "12.73"[1] => 문자열 (5) "23.99"[2] => 문자열 (1) "1"} [ "가격"] => 배열 (3) {[0] => 5) "11.76"}}
클래스를 만들 때 $ _SESSION 값이 올바르게 설정되었고 세션이 시작 되었습니까? –
왜 "$ totalcost; $ i;"라고 쓰셨습니까? 및 "$ numitems; $ i;" 명시 적으로 함수에서? –
@OM 영원성 모자는 자바에서 그것을하는 데 익숙한 방법입니다. – eoin