Is there a way to also pass and receive the custom variable (for example payer's username)? I cant force my users to use the same email address for paypal (which is originally returned by paypal) as they use on my site. Passing an additional username would be a great help for easily checking the payer's identity.
You can include a custom hidden field in the form that is posted to PayPal, like this:
<input type="hidden" name="custom" value="<?php echo $user_name; ?>"> // I don't know php well, so correct that part if it's wrong
PayPal will then pass that value back to you with the rest of the IPN data. Note that the maximum number of characters permitted for this field is 256.
Also, you can't define just any field - you can only use the ones that PayPal specifies here (i.e. the input name
is 'custom' because PayPal specifically allows it - if you had set the name
to 'username' it would be ignored).