Log in

View Full Version : $_POST and $HTTP_POST_VARS



borris83
03-27-2009, 07:12 AM
Hi, I am familiar with $_POST since I use 'POST' method in lot of forms and process them in PHP pages...

But, what is $HTTP_POST_VARS? Is it same as $_POST

techietim
03-27-2009, 10:00 AM
That was the PHP 3 way of doing it. Just ignore it; it's old and deprecated.

Ahmed Saleh
03-27-2009, 12:16 PM
Yes Forget it and use $_POST[] .

borris83
03-27-2009, 01:27 PM
Hi, can I post the values of $_POST to a php page without a form...

when I click on 'submit' in a html form, it posts the name of each input fields and their values to the url mentioned in the 'action' attribute of form tag...

Can I directly post these values to the url without a html form?

Lpe04
03-27-2009, 01:55 PM
yes, using something like curl (which mimics a browser)

Also you can your $_REQUEST instead of $_POST if you like, but like mentioned the $HTTP_POST_VARS is just outdated.

Cheers,

Nile
03-27-2009, 02:25 PM
You can also use Ajax to send post values to a php page.



vars.open("POST", "file.php", null);
vars.send(parameters);

borris83
03-27-2009, 03:03 PM
isn't there any way in php itself to send some $_POST values to another php page?

When you set up IPN for Paypal, we must post some values to the url mentioned in paypal. I know that I can create a form and give the parameters as names for the input fields. But is there any alternative?


I saw this sample code in paypal which actually posts the value without actually submitting a form, can you explain how it does this without submitting:

// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';

foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}

// post back to PayPal system to validate
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);

// assign posted variables to local variables
$item_name = $_POST['item_name'];
$item_number = $_POST['item_number'];
$payment_status = $_POST['payment_status'];
$payment_amount = $_POST['mc_gross'];
$payment_currency = $_POST['mc_currency'];
$txn_id = $_POST['txn_id'];
$receiver_email = $_POST['receiver_email'];
$payer_email = $_POST['payer_email'];

if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
// check the payment_status is Completed
// check that txn_id has not been previously processed
// check that receiver_email is your Primary PayPal email
// check that payment_amount/payment_currency are correct
// process payment
}
else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation
}
}
fclose ($fp);
}
?>

Nile
03-27-2009, 03:53 PM
yes, using something like curl (which mimics a browser)

Also you can your $_REQUEST instead of $_POST if you like, but like mentioned the $HTTP_POST_VARS is just outdated.

Cheers,

Did you read that post? It is possible to send post data with no forums in PHP, using curl(). (http://us3.php.net/manual/en/book.curl.php)

When pasting a code, please remember to use [code] tags. That includes [ html ], [ code ], and [ php ].

borris83
03-27-2009, 04:08 PM
Yes, I read the post about 'curl'. I looked that up in www.php.net and it seems that I have spend a little time in learning. Also, thanks for letting me know how to insert code in my post.

Now the code that I have pasted, doesn't it actually post the data to paypal url without curl()?

Can u please tell me what does the following line do?


fputs ($fp, $header . $req)

CrazyChop
03-28-2009, 07:00 AM
isn't there any way in php itself to send some $_POST values to another php page?

When you set up IPN for Paypal, we must post some values to the url mentioned in paypal. I know that I can create a form and give the parameters as names for the input fields. But is there any alternative?


I saw this sample code in paypal which actually posts the value without actually submitting a form, can you explain how it does this without submitting:

// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';

foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}

// post back to PayPal system to validate
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);

..snipped...



That is using sockets. Not that whether cURL is better than sockets, just that when using sockets you have to write the headers correctly, which can be a pain, while cURL just let you set options - lots of them - which is just another pain.

CrazyChop
03-31-2009, 04:18 PM
fputs ($fp, $header . $req)

This one basically send the the string which is a combination of $header and $request to the destination to the socket. (Note: This is the same principle as writing to a file). $fp points to a paypal script; you are sending the header info (represented by the $header string) and the post data across.

The header indicates that the incoming data is post data. So basically, you are sending information to paypal.