我试图通过HTML表单将一些变量发送到另一个PHP页面, 我不是PHP方面的专家,但我知道在大多数日子里能帮到我, 并且在其他情况下没有问题,
但是,唉,PHP不是我的事情,所以我在这里向编码世界的大师们询问一颗智慧之珠,
好的,让我为你分解一下,
我有一个PHP IPN(PayPal)页面,在客户进行购买时执行,原始代码只检查成功销售,然后相应地向我自己和用户发送一些电子邮件,
我还有一个自动生成许可证的许可脚本,
我在页面中使用HTML表单,以便在销售被标记为成功时生成许可证并在发送电子邮件的同时发送给用户,
所有非常基本的东西,并且已经在其他3个脚本中使用它没有任何问题,但由于某些原因我这次无法理解它,并且似乎无法使其工作,
我联系了我的商店脚本的作者,以确保我在表单中使用了正确的变量,他说所需的变量是:
$usr->username
$usr->email
$crow->title
这是IPN页面:
<?php
define("_VALID_PHP", true);
define("_PIPN", true);
ini_set('log_errors', true);
ini_set('error_log', dirname(__file__) . '/ipn_errors.log');
if (isset($_POST['payment_status'])) {
require_once ("../../init.php");
include (BASEPATH . 'lib/class_pp.php');
$demo = getValue("demo", Content::gTable, "name = 'paypal'");
$listener = new IpnListener();
$listener->use_live = $demo;
$listener->use_ssl = false;
$listener->use_curl = true;
try {
$listener->requirePostMethod();
$ppver = $listener->processIpn();
}
catch (exception $e) {
error_log($e->getMessage());
exit(0);
}
$payment_status = $_POST['payment_status'];
$receiver_email = $_POST['receiver_email'];
$payer_email = $_POST['payer_email'];
$payer_status = $_POST['payer_status'];
$mc_currency = $_POST['mc_currency'];
$mc_fee = isset($_POST['mc_fee']) ? floatval($_POST['mc_fee']) : 0.00;
list($user_id, $sesid) = explode('_', $_POST['custom']);
$mc_gross = $_POST['mc_gross'];
$txn_id = $_POST['txn_id'];
$getxn_id = $core->verifyTxnId($txn_id);
$cartrow = $content->getCartContent($sesid);
$totalrow = Content::getCart($sesid);
$v1 = compareFloatNumbers($mc_gross, $totalrow->totalprice, "=");
$items = array();
$pp_email = getValue("extra", Content::gTable, "name = 'paypal'");
if ($ppver) {
if ($_POST['payment_status'] == 'Completed') {
if ($receiver_email == $pp_email && $v1 == true && $getxn_id == true) {
if ($cartrow) {
foreach ($cartrow as $crow) {
$data = array(
'txn_id' => sanitize($txn_id),
'pid' => $crow->pid,
'uid' => intval($user_id),
'downloads' => 0,
'file_date' => time(),
'ip' => sanitize($_SERVER['REMOTE_ADDR']),
'created' => "NOW()",
'payer_email' => sanitize($payer_email),
'payer_status' => sanitize($payer_status),
'item_qty' => $crow->total,
'price' => $crow->total * $crow->price,
'coupon' => $totalrow->coupon,
'tax' => $totalrow->totaltax,
'mc_fee' => $mc_fee,
'currency' => sanitize($mc_currency),
'pp' => "PayPal",
'status' => 1,
'active' => 1);
$items[$crow->price] = $crow->title;
$db->insert(Products::tTable, $data);
}
unset($crow);
$xdata = array(
'invid' => date('Ymd').$db->insertid(),
'user_id' => intval($user_id),
'items' => serialize($items),
'coupon' => $totalrow->coupon,
'originalprice' => $totalrow->originalprice,
'tax' => $totalrow->tax,
'totaltax' => $totalrow->totaltax,
'total' => $totalrow->total,
'totalprice' => $totalrow->totalprice,
'currency' => sanitize($_POST['currency_code']),
'created' => "NOW()",
);
$db->insert(Content::inTable, $xdata); }
/* == Notify Administrator == */
require_once (BASEPATH . "lib/class_mailer.php");
$row2 = Core::getRowById(Content::eTable, 5);
$usr = Core::getRowById(Users::uTable, $user_id);
$body = str_replace(array(
'[USERNAME]',
'[STATUS]',
'[PRODUCT]',
'[TOTAL]',
'[PP]',
'[IP]'), array(
$usr->username,
"Completed",
$crow->title,
$totalrow->totalprice,
"PayPal",
$_SERVER['REMOTE_ADDR']), $row2->body);
$newbody = cleanOut($body);
$mailer = Mailer::sendMail();
$message = Swift_Message::newInstance()
->setSubject($row2->subject)
->setTo(array($core->site_email => $core->site_name))
->setFrom(array($core->site_email => $core->site_name))
->setBody($newbody, 'text/html');
$mailer->send($message);
/* == Notify User == */
$row3 = Core::getRowById(Content::eTable, 8);
$val = '
<table border="0" cellpadding="4" cellspacing="2">';
$val .= '
<thead>
<tr>
<td width="20"><strong>#</strong></td>
<td class="header">' . Lang::$word->PRD_NAME . '</td>
<td class="header">' . Lang::$word->PRD_PRICE . '</td>
<td class="header">' . Lang::$word->TXN_QTY . '</td>
<td class="header">' . Lang::$word->CKO_TPRICE . '</td>
</tr>
</thead>
<tbody>
';
$i = 0;
foreach ($cartrow as $ccrow) {
$i++;
$val .= '
<tr>
<td style="border-bottom-width:1px; border-bottom-color:#bbb; border-bottom-style:dashed">' . $i . '.</td>
<td style="border-bottom-width:1px; border-bottom-color:#bbb; border-bottom-style:dashed">' . sanitize($ccrow->title, 30, false) .
'</td>
<td style="border-bottom-width:1px; border-bottom-color:#bbb; border-bottom-style:dashed">' . $core->formatMoney($ccrow->price) .
'</td>
<td align="center" style="border-bottom-width:1px; border-bottom-color:#bbb; border-bottom-style:dashed">' . $ccrow->total . '</td>
<td align="right" style="border-bottom-width:1px; border-bottom-color:#bbb; border-bottom-style:dashed">' . $core->formatMoney($ccrow-
>total * $ccrow->price) . '</td>
</tr>
';
}
unset($ccrow);
$val .= '
<tr>
<td colspan="4" align="right" valign="top" style="border-bottom-width:1px; border-bottom-color:#bbb; border-bottom-
style:dashed"><strong>';
$val .= Lang::$word->CKO_SUBT . ':<br />';
$val .= Lang::$word->CKO_DISC . ':<br />';
$val .= Lang::$word->VAT . ':<br />
</strong></td>
<td align="right" valign="top" style="border-bottom-width:1px; border-bottom-color:#bbb; border-bottom-style:dashed"><strong>';
$val .= $core->formatMoney($totalrow->originalprice) . '<br />';
$val .= '- ' . $core->formatMoney($totalrow->coupon) . '<br />';
$val .= '+ ' . $core->formatMoney($totalrow->total * $totalrow->tax) . '<br />
</strong>';
$val .= ' </td>
</tr>
<tr>
<td colspan="4" align="right" valign="top"><strong style="color:#F00">' . Lang::$word->CKO_GTOTAL . ':</strong></td>
<td align="right" valign="top"><strong style="color:#F00">' . $core->formatMoney($totalrow->tax * $totalrow->total + $totalrow->total)
. '</strong></td>
</tr>
</tbody>
</table>';
$body3 = str_replace(array(
'[USERNAME]',
'[ITEMS]',
'[SITE_NAME]',
'[URL]'), array(
$usr->username,
$val,
$core->site_name,
SITEURL), $row3->body);
$newbody2 = cleanOut($body3);
$mailer2 = Mailer::sendMail();
$message2 = Swift_Message::newInstance()
->setSubject($row3->subject)
->setTo(array($usr->email => $usr->username))
->setFrom(array($core->site_email => $core->site_name))
->setBody($newbody2, 'text/html');
$mailer2->send($message2);
$db->delete(Content::crTable, "user_id='" . $sesid . "'");
$db->delete(Content::exTable, "user_id='" . $sesid . "'");
$db->delete(Products::rTable, "user_id='" . $sesid . "'");
?>
<!doctype html>
<html>
<head></head>
<body onload="document.createElement('form').submit.call(document.getElementById('Form'))">
<form id='Form' name='form' action='http://www.****************.php' method='post'>
<input type='hidden' name='name' value='<?php echo $_POST['usr->username'];?>'>
<input type='hidden' name='email' value='<?php echo $_POST['usr->email'];?>'>
<input type='hidden' name='original_url' value='http://www.****************ipn.php'>
<input type='hidden' name='projname' value='<?php echo $_POST['crow->title'];?>'>
<input type=hidden name="submit" id="submit" value="Continue"/>
</form>
</body>
</html>
<?php
$sale_amount = '$totalrow->totalprice';
$product = '$crow->title';
include('/home/**********************************.php');
}
} else {
/* == Failed Transaction= = */
require_once (BASEPATH . "lib/class_mailer.php");
$row = Core::getRowById(Content::eTable, 6);
$usr = Core::getRowById(Users::uTable, $user_id);
$body = str_replace(array('[USERNAME]','[STATUS]','[TOTAL]','[PP]','[IP]'), array(
$usr->username,"Failed",$core->formatMoney($gross),"PayPal",$_SERVER['REMOTE_ADDR']), $row->body);
$newbody = cleanOut($body);
$mailer = Mailer::sendMail();
$message = Swift_Message::newInstance()
->setSubject($row->subject)
->setTo(array($core->site_email => $core->site_name))
->setFrom(array($core->site_email => $core->site_name))
->setBody($newbody, 'text/html');
$mailer->send($message);
}
}
}
?>
这里是使用的FORM代码:
<!doctype html>
<html>
<head></head>
<body onload="document.createElement('form').submit.call(document.getElementById('Form'))">
<form id='Form' name='form' action='http://www.****************.php' method='post'>
<input type='hidden' name='name' value='<?php echo $_POST['usr->username'];?>'>
<input type='hidden' name='email' value='<?php echo $_POST['usr->email'];?>'>
<input type='hidden' name='original_url' value='http://www.****************ipn.php'>
<input type='hidden' name='projname' value='<?php echo $_POST['crow->title'];?>'>
<input type=hidden name="submit" id="submit" value="Continue"/>
</form>
</body>
</html>
我也知道我可能需要使用foreach()循环,但是当我到达那里时,我可能需要先解决这个问题。
所以我们有,我想我已经留下了足够的信息,细节和代码, 如果我错过任何可能有帮助的事情让我知道
答案 0 :(得分:1)
使用时
<input type="hidden" name="name" value="<?php echo $_POST['usr->username'];?>">
你正在调用一个POST变量'usr-&gt; username',就我在你的脚本中看到的而言,它不存在。相反,使用这个:
<input type="hidden" name="name" value="<?php echo $usr->username;?>">
这会将输入的值设置为您在行上定义的'usr'对象的属性'username':
$usr = Core::getRowById(Users::uTable, $user_id);
这同样适用于其他领域。
希望有所帮助:)
此致