Help sending variables on redirect

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
socc3r
Forum Newbie
Posts: 4
Joined: Tue Jun 08, 2010 11:13 am

Help sending variables on redirect

Post by socc3r »

Hey,

I am new here (and to PHP for the most part) so let me thank everyone in advance.
Here is my situation.

I am trying to set up a system in which someone registers at my site with their name and e-mail, and I send them an automatic message in response. In that e-mail I want to have a link (via a button I created) in which someone can go to my merchant account site and purchase my service with a credit card. I already have the account and all, but the Script the merchant account provided will not work in e-mails. They said I have to have the user click my link from a website - I am trying to avoid having the user go through this extra step.

What I would like to do, is have the e-mail set up so they click a link that takes them to a site on my server. I then want the site to AUTOMATICALLY redirect them to my checkout site - thus avoiding the problem of having the "check-out" button in an e-mail. Is this possible?

Here is the script the merchant account provided.

Code: Select all

<?PHP
// This sample code requires the mhash library for PHP versions older than
// 5.1.2 - http://hmhash.sourceforge.net/
	
// the parameters for the payment can be configured here
// the API Login ID and Transaction Key must be replaced with valid values
$loginID		= "API_LOGIN_ID";
$transactionKey = "TRANSACTION_KEY";
$amount 		= "19.99";
$description 	= "Sample Transaction";
$label 			= "Submit Payment"; // The is the label on the 'submit' button
$testMode		= "false";
// By default, this sample code is designed to post to our test server for
// developer accounts: https://test.authorize.net/gateway/transact.dll
// for real accounts (even in test mode), please make sure that you are
// posting to: https://secure.authorize.net/gateway/transact.dll
$url			= "https://test.authorize.net/gateway/transact.dll";

// If an amount or description were posted to this page, the defaults are overidden
if ($_REQUEST["amount"])
	{ $amount = $_REQUEST["amount"]; }
if ($_REQUEST["description"])
	{ $description = $_REQUEST["description"]; }

// an invoice is generated using the date and time
$invoice	= date(YmdHis);
// a sequence number is randomly generated
$sequence	= rand(1, 1000);
// a timestamp is generated
$timeStamp	= time ();

// The following lines generate the SIM fingerprint.  PHP versions 5.1.2 and
// newer have the necessary hmac function built in.  For older versions, it
// will try to use the mhash library.
if( phpversion() >= '5.1.2' )
{	$fingerprint = hash_hmac("md5", $loginID . "^" . $sequence . "^" . $timeStamp . "^" . $amount . "^", $transactionKey); }
else 
{ $fingerprint = bin2hex(mhash(MHASH_MD5, $loginID . "^" . $sequence . "^" . $timeStamp . "^" . $amount . "^", $transactionKey)); }

// Print the Amount and Description to the screen.
echo "Amount: $amount <br />";
echo "Description: $description <br />";

// Create the HTML form containing necessary SIM post values
echo "<FORM method='post' action='$url' >";
// Additional fields can be added here as outlined in the SIM integration guide
// at: http://developer.authorize.net
echo "	<INPUT type='hidden' name='x_login' value='$loginID' />";
echo "	<INPUT type='hidden' name='x_amount' value='$amount' />";
echo "	<INPUT type='hidden' name='x_description' value='$description' />";
echo "	<INPUT type='hidden' name='x_invoice_num' value='$invoice' />";
echo "	<INPUT type='hidden' name='x_fp_sequence' value='$sequence' />";
echo "	<INPUT type='hidden' name='x_fp_timestamp' value='$timeStamp' />";
echo "	<INPUT type='hidden' name='x_fp_hash' value='$fingerprint' />";
echo "	<INPUT type='hidden' name='x_test_request' value='$testMode' />";
echo "	<INPUT type='hidden' name='x_show_form' value='PAYMENT_FORM' />";
echo "	<input type='submit' value='$label' />";
echo "</FORM>";
?>
Obviously I there is sensitive information that I took out. I tested this code on my web server it worked fine, I just want to know if I can automatically redirect it.

Thanks!
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Help sending variables on redirect

Post by AbraCadaver »

Why can't you just put a link to this form in the email?
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
socc3r
Forum Newbie
Posts: 4
Joined: Tue Jun 08, 2010 11:13 am

Re: Help sending variables on redirect

Post by socc3r »

The form itself is not hosted on my server. It is on the bank's server. The API login and all have to be passed to the bank's site to create the login ability. That was what I had wanted to do, but the bank said its not set up to be able to be linked to in an e-mail? It didn't make sense to me either.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Help sending variables on redirect

Post by AbraCadaver »

socc3r wrote:The form itself is not hosted on my server. It is on the bank's server. The API login and all have to be passed to the bank's site to create the login ability. That was what I had wanted to do, but the bank said its not set up to be able to be linked to in an e-mail? It didn't make sense to me either.
The form that you posted above is hosted on your server yes? If so, then the link in the email would be: [text] http://www.yourdomainname.com/the_form_above.php[/text]
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
socc3r
Forum Newbie
Posts: 4
Joined: Tue Jun 08, 2010 11:13 am

Re: Help sending variables on redirect

Post by socc3r »

The form is yes. But if you look, that script simply generates ANOTHER button the user would have to click to then be redirected to the actual checkout page, hosted by the authorize.net
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Help sending variables on redirect

Post by AbraCadaver »

socc3r wrote:The form is yes. But if you look, that script simply generates ANOTHER button the user would have to click to then be redirected to the actual checkout page, hosted by the authorize.net
Yep, that's how you'll do it. As they stated, it will probably match your website as a referrer with your api key etc... Sorry I misunderstood at first.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
socc3r
Forum Newbie
Posts: 4
Joined: Tue Jun 08, 2010 11:13 am

Re: Help sending variables on redirect

Post by socc3r »

No problem - Thanks for your help though!
Post Reply