/    Sign up×
Community /Pin to ProfileBookmark

Need help passing a variable

Here is the gist of what I am doing…

1)php script in which variable $id is defined….
2)client clicks BIN and goes to Paypal…
3)on my return page I need to use the variable $id

I have had no success trying to use the Paypal verification scripts and I don’t need any complicated verification thing.

Is there a way to have the variable pass to Paypal and then have Paypal pass it back? Or, do I make it a global variable, and if so, how do I do that?

Thanks!
Dr. Marie.

to post a comment
PHP

17 Comments(s)

Copy linkTweet thisAlerts:
@adam_jimenezMay 28.2009 — this can be done with paypal's "instant payment notification", which can be enabled in paypal's preferences.

paypal can pass back a variable called $_POST['item_number']

just include it when you post to paypal e.g.

<form method="post" action="https://www.paypal.com/cgi-bin/webscr">

<input type="hidden" name="cmd" value="_xclick">

<input type="hidden" name="item_name" value="Basket contents">

<input type="hidden" name="item_number" value="<?php echo $order_id;?>">

etc
Copy linkTweet thisAlerts:
@DrMarieauthorMay 28.2009 — Thanks Adam...I just have a couple of questions...

I am assuming that I put $_POST['item number'] in the box for advanced variables when I am making my paypal button? Do I have to put:

$id=$_POST['item number']

or just

$_POST['item number']

And then I am assuming that on my return page I do $id=$_GET['item number']

Thanks for your help...I find the Paypal stuff confusing.
Copy linkTweet thisAlerts:
@adam_jimenezMay 28.2009 — $_POST['item_number'] is used on the return page and will give the value of the id that you passed to paypal.
Copy linkTweet thisAlerts:
@DrMarieauthorMay 28.2009 — Does paypal pass it back automatically or do I need to put something in the section for advanced variables on my button?
Copy linkTweet thisAlerts:
@adam_jimenezMay 28.2009 — paypal will pass it back automatically as long as u have:

<input type="hidden" name="item_number" value="<?php echo $order_id;?>">
Copy linkTweet thisAlerts:
@DrMarieauthorJun 01.2009 — I'm still having problems with this. It turned out that part of my problem was that I had a button stored at paypal which didn't allow me to add any code to the form. So, I managed to change the button so it wasn't stored and I can see that my info is getting to Paypal, but Paypal doesn't pass it back.

Any ideas?
Copy linkTweet thisAlerts:
@DrMarieauthorJun 01.2009 — No I don't think so. How do I do that?
Copy linkTweet thisAlerts:
@adam_jimenezJun 01.2009 — Login to your PayPal account, go to the profile page, and click on "Instant Payment Notification Preferences" link. Click on "Edit" button to setup new IPN preferences.
Copy linkTweet thisAlerts:
@DrMarieauthorJun 01.2009 — Thanks for your speedy help adam! I see the spot where I enable IPN but where it asks me for a notification URL do I enter my return page?
Copy linkTweet thisAlerts:
@adam_jimenezJun 01.2009 — yep - that should point to a script that handles the paypal response.

note that the purchaser will never see this page - so it shouldn't be a thank u page.
Copy linkTweet thisAlerts:
@DrMarieauthorJun 01.2009 — Oh man, I was trying to avoid setting up a page for paypal response as I got really confused when I did it. I guess I'll start looking into how to do that.
Copy linkTweet thisAlerts:
@adam_jimenezJun 01.2009 — [code=php] // 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.0rn";
$header .= "Content-Type: application/x-www-form-urlencodedrn";
$header .= "Content-Length: " . strlen($req) . "rnrn";
$fp = fsockopen ('www.paypal.com', 80, $errno, $errstr, 30);

$verified=false;
if( !$fp ){
// HTTP ERROR
}else{
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if( strcmp($res, "VERIFIED") == 0 ){
$verified=true;
}
$msg.=$res;
}
fclose ($fp);
}

if( !$verified ){
// order not verified
exit;
}

//add code here to process order - id is stored in $_POST['item_number']
[/code]
Copy linkTweet thisAlerts:
@DrMarieauthorJun 01.2009 — Hey thanks! I'll work on this some more tonight. I'll let you know how things go!

Marie
Copy linkTweet thisAlerts:
@DrMarieauthorJun 03.2009 — Ugh....still struggling. I used the above code and turned on my IPN and had it send to the page I made with that code. I also changed my successful payment return from paypal to that page.

I added the following to the bottom:

[code=php]$id=$_POST['item_number'];


header("location: http://www.mydomain.com/view_answer.php?id=$id);
[/code]


However, it doesn't verify.
Copy linkTweet thisAlerts:
@DrMarieauthorJun 03.2009 — OK, I finally got it to work. Just in case anyone else has this problem I had to turn on automatic return in my paypal profile. Then, specify the url to return to (which is not the verify url).

Then, I made my return url something like this: value="http://mydomain.com/return_url?id=<?php echo '$id';?>">
Copy linkTweet thisAlerts:
@MindzaiJun 03.2009 — ^^

You probably don't want those single quotes around $id.
×

Success!

Help @DrMarie spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...