I played with this for ages before I realized that you can send predefined PayPal variables and not create your own.
They are listed here https://www.paypal.com/cgi-bin/webscr?cmd=p/pdn/howto_checkout-outside
The one you can use for a custom variable is called "custom"
<input type="hidden" name="custom" value="<?=$twitId;?>">
You also need to make sure that you use this button.
<input type="hidden" name="cmd" value="_s-xclick">
You also need to enable and set the URL for instant payment alerts in PayPal
They call it a listener, but it really just sends the payment details to the PayPal page. Please note that this is not the URL at which the customer returns after the payment is completed, as indicated in the button settings.
Get a user variable in PHP this way
$userID = $_POST[custom];
Full instructions are here http://www.brianmoreau.com/articles/paypal_buy_now_button_sending_custom_variables.php
I hope this saves you from the many hours I spent on it.
This method also allows you to get buyer's details, such as email address and transaction address and link.
To view the full data sent after payment by clicking on the history, IPN history
source share