晚上全部。我想要做的是在用户点击了paypal的'buynow'按钮后,首先转到存储已在数据库中购买的商品的页面,然后重定向到paypal付款。
这就是我所拥有的:
<?php
if(isset($_POST['cmd']) && isset($_POST['hosted_button_id']) && isset($_POST['diskSpace']) && isset($_POST['bandwidth']) && isset($_POST['subdomains']) && isset($_POST['additionalftp']) && isset($_POST['mysqldatabases']) && isset($_POST['emailforwarding']) && isset($_POST['autoresponders']) && isset($_POST['emaildistribution']) && isset($_POST['mailboxes']) && isset($_POST['oneclick']) && isset($_POST['operatingsystem'])){
$cmd = $_POST['cmd'];
$custom = md5(date("his").microtime());
$hosted_button_id = $_POST['hosted_button_id'];
$diskSpace = $_POST['diskSpace'];
$bandwidth = $_POST['bandwidth'];
$subdomains = $_POST['subdomains'];
$additionalftp = $_POST['additionalftp'];
$mysqldatabases = $_POST['mysqldatabases'];
$emailforwarding = $_POST['emailforwarding'];
$autoresponders = $_POST['autoresponders'];
$emaildistribution = $_POST['emaildistribution'];
$mailboxes = $_POST['mailboxes'];
$oneclick = $_POST['oneclick'];
$operatingsystem = $_POST['operatingsystem'];
$con = mysql_connect('localhost', '', '');
$db = mysql_select_db('', $con);
if(!mysql_query("SELECT * FROM `hostingAccounts` ORDER BY id")){
$createTable = ("CREATE TABLE IF NOT EXISTS `hostingAccounts` (
`id` INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`ref` TEXT NOT NULL,
`disk_space` TEXT NOT NULL,
`bandwidth` TEXT NOT NULL,
`sub_domains` TEXT NOT NULL,
`additional_ftp` TEXT NOT NULL,
`mysql_databases` TEXT NOT NULL,
`email_forwarding` TEXT NOT NULL,
`auto_responders` TEXT NOT NULL,
`email_distribution` TEXT NOT NULL,
`mailboxes` TEXT NOT NULL,
`one_click_apps` TEXT NOT NULL,
`operating_system` TEXT NOT NULL,
`payer_email` TEXT NOT NULL,
`first_name` TEXT NOT NULL,
`last_name` TEXT NOT NULL,
`payer_id` TEXT NOT NULL,
`address_street` TEXT NOT NULL,
`address_city` TEXT NOT NULL,
`address_state` TEXT NOT NULL,
`address_zip` TEXT NOT NULL,
`address_country` TEXT NOT NULL
) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_general_ci;");
mysql_query($createTable);
}
mysql_query("INSERT INTO `hostingAccounts` (ref, disk_space, bandwidth, sub_domains, additional_ftp, mysql_databases, email_forwarding, auto_responders, email_distribution, mailboxes, one_click_apps, operating_system) VALUES ('$custom', '$diskspace', '$bandwidth', '$subdomains', '$additionalftp', '$mysqldatabases', '$emailforwarding', '$autoresponders', '$emaildistribution', '$mailboxes', '$oneclick', '$operatingsystem')") or die (mysql_error());
$host = "https://www.paypal.com";
$path = "/cgi-bin/webscr";
$data = "cmd=".$cmd."&hosted_button_id=".$hosted_button_id."&custom=".$custom;
$data = urlencode($data);
header("POST $path HTTP/1.1\r\n" );
header("Host: $host\r\n" );
header("Content-type: application/x-www-form-urlencoded\r\n" );
header("Content-length: " . strlen($data) . "\r\n" );
header("Connection: close\r\n\r\n" );
header($data);
}
?>
问题是它出现了“内部服务器错误”。谁能看到我做错了什么?
答案 0 :(得分:0)
编辑:
header("POST $path HTTP/1.1\r\n" );
如果您想在脚本中使用POST,可以尝试使用curl_ *系列函数。
此外,您需要尝试清理客户的输入:
$cmd = $_POST['cmd'];
另外,为什么不自己创建表。选择每个请求需要花费很多不必要的开销:(更不用说非常不可思议了 - 你的代码中有你的数据库架构......)
if(!mysql_query("SELECT * FROM `hostingAccounts` ORDER BY id")){
$createTable = ("CREATE TABLE IF NOT EXISTS `hostingAccounts` (
`id` INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
答案 1 :(得分:0)
header()无法对其他服务器执行POST操作 使用curl或Zend_Http或PEAR的Http_Client
答案 2 :(得分:0)
你能告诉我为什么这不会重定向吗?
$sendTo = "https://www.paypal.com/cgi-bin/webscr"
$header[] = "Content-type: text/html";
$dataArray[] = "cmd=".$cmd;
$dataArray[] = "hosted_button_id=".$hosted_button_id;
$dataArray[] = "custom=".$custom;
$post = implode($dataArray, '&');
$post = urlencode($post);
$ch = curl_init();
curl_setopt($ch, CURLOPT_CONNECTIONTIMEOUT, 30);
curl_setopt($ch, CURLOPT_FAILONERROR, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
die();