我对这个脚本有一个奇怪的问题。我可以使用以下网址直接发布到该网址:" http://example.com/script.php?payer_email=foo&txn_id=9229fjfua822"。但是尝试发布相同的数据让我们说http://requestmaker.com变量中没有显示任何内容。我在PHP5中使用nginx。
<?php
$panel_url = 'http://example.com:23462/';
$username = $_GET['payer_email'];
$invoice = $_GET['txn_id'];
$trimmedinvoice = substr($invoice, -6);
$password = $trimmedinvoice;
$max_connections = 1;
$reseller = 0;
$bouquet_ids = array(
1,
2,
3 );
$expirationdays = $_GET['custom'];
$expiration = "+$expirationdays day";
$expiredate = strtotime($expiration);
###############################################################################
$post_data = array( 'user_data' => array(
'username' => $username,
'password' => $password,
'max_connections' => $max_connections,
'is_restreamer' => $reseller,
'exp_date' => $expiredate,
'bouquet' => json_encode( $bouquet_ids ) ) );
$opts = array( 'http' => array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => http_build_query( $post_data ) ) );
$context = stream_context_create( $opts );
$api_result = json_decode( file_get_contents( $panel_url . "api.php?action=user&sub=create", false, $context ) );
Echo "<b>Username:</b> <br>";
echo $username;
echo "<br></br>";
echo "<b>Password:<br></b>";
echo $password;
echo "<br></br>";
echo "<b>Expires (in unix time):<br></b>";
echo $expiredate;
?>
整晚都在测试,发现添加此代码会返回正常传递的数据。所以问题似乎是脚本,而不是设置本身。我无法弄清楚我哪里出错了。
print "CONTENT_TYPE: " . $_SERVER['CONTENT_TYPE'] . "<BR />";
$data = file_get_contents('php://input');
print "DATA: <pre>";
var_dump($data);
var_dump($_POST);
print "</pre>";
直接使用网址发布的最后一段代码输出:
CONTENT_TYPE:
DATA:
string(0) ""
array(0) {
}
使用外部海报(如请求者)发布最后一段代码:
CONTENT_TYPE:
text/html<BR />
DATA: <pre>string(35) "payer_email=foo&txn_id=9229fjfua822"
array(0) {
}
答案 0 :(得分:1)