Jump to content

[SOLVED] I'm sure this should be simple but i cant work it out


Hearnah

Recommended Posts

hi!

 

I'm Danny :-)

 

Basically, i have a small problem, where I have a paypal button which goes to a payment screen (the basic button)

 

But what i would like to do, is when the button is clicked, a script triggers to add into my database,

 

i can do all it apart from work out how to get the script to trigger, and still go to the paypal link

 

For instance

 

                    [link]

                      /\

                    /  \

[add to database] \

                          [go to paypal for payment]

 

 

Thanks in advance!

 

Dan

Well it's sort of working,

 

it's adding into the database and it's also redirecting to paypal, but it's not taking the $_POST with it

 

right at the top

<?php
header("Location: https://www.paypal.com/cgi-bin/webscr");
include("include/session.php");
?>

 

then where it grabs all from the submitted page

<?php
$cmd = mysql_escape_string($_POST['cmd']);
$encrypted = mysql_escape_string($_POST['encrypted']);
$cdomain = mysql_escape_string($_POST['cdomain']);
$sdomain = mysql_escape_string($_POST['sdomain']);
$result = mysql_query("INSERT into domains (username, active, sdomain, cdomain)
VALUES ('$session->username','n','$sdomain','$cdomain')");
?>

 

But i'm not sure how to now send $cmd and $encrypted with

header('Location: https://www.paypal.com/cgi-bin/webscr');

you can either use javascript quite complicated or you can use this (i just found this snippet):

 

<?php
$url = 'Location: https://www.paypal.com/cgi-bin/webscr';  
$fields = array(  
'cmd'=>urlencode($_POST['cmd']),  
'encrypted'=>urlencode($_POST['encrypted'])
);  
  
//url-ify the data for the POST  
$fields_string = null;
foreach($fields as $key=>$value){
$fields_string .= $key.'='.$value.'&';
}  
rtrim($fields_string,'&');  
  
//open connection  
$ch = curl_init();  
  
//set the url, number of POST vars, POST data  
curl_setopt($ch,CURLOPT_URL,$url);  
curl_setopt($ch,CURLOPT_POST,count($fields));  
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);  
  
//execute post  
$result = curl_exec($ch);  
  
//close connection  
curl_close($ch);  
?>

 

FYI This uses a php extension called libcurl. You may have to download/enable this extension by going into php.ini and find/add the following line:

[php_CURL]
extension=php_curl.dll

if it exists make sure it reads exactly like the above example.

---------

 

there may be simpler solutions that paypal may have thought of. like using GET variables instead of POST. and there may be a solution like above that does not need any non-default extensions like libcurl.

 

 

hope this helps,

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.