hrdy
hrdy

Reputation: 138

PHP $get_ empty when data is posted from website, but not manual url

I have an odd problem with this script. I can post directly to it using the URL: "http://example.com/script.php?payer_email=foo&txn_id=9229fjfua822". But trying to post the same data from lets say http://requestmaker.com nothing is showing in the variable(s). I'm using nginx with PHP5.

<?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;

?>

Been testing all night and found that adding this code will return the data being passed without problems. So the problem seems to be with the script, not the setup itself. Just can't figure where I'm going wrong.

print "CONTENT_TYPE: " . $_SERVER['CONTENT_TYPE'] . "<BR />";
$data = file_get_contents('php://input');
print "DATA: <pre>";
var_dump($data);
var_dump($_POST);
print "</pre>";

Output from the last block of code posting directly with the URL:

CONTENT_TYPE: 
DATA:
string(0) ""
array(0) {
}

Output from the last block of code posting using an external poster like the requestmaker:

CONTENT_TYPE:
text/html<BR />
DATA: <pre>string(35) "payer_email=foo&txn_id=9229fjfua822"
array(0) {
}

Upvotes: 1

Views: 110

Answers (1)

Richard Smith
Richard Smith

Reputation: 49752

POST variables are in $_POST not $_GET (the latter contains the arguments appended to the URI).

You could use $_REQUEST which contains both POST and GET variables.

See this document for more.

Upvotes: 1

Related Questions