tags:

views:

54

answers:

3

Look at my code below

<a href="https://secure.gate2shop.com/ppp/purchase.do?merchant_id=234555454545433&amp;merchant_site_id=54443¤cy=USD&amp;total_amount=39.99&amp;item_name_1=IncidentSupportTier1&amp;item_amount_1=39.99&amp;item_quantity_1=1&amp;checksum=**call php function to get the checksum value**&time_stamp=2010-06-14.14:34:33&version=3.0.0"
onmouseover="document.myform.sub_but.src='checkout02.jpg'"
onmouseout="document.myform.sub_but.src='butup.gif'"
onclick="return val_form_this_page()">

<img src="http://www.techvedic.com/gifs/checkout02.jpg"
width="143" height="39" border="0" alt="Submit this form"
name="sub_but" />

On button click the href link will open. But before opening the link I need to calculate the cheksum. I know how to calculate it in PHP script. But please tell me how can I call the PHP function which will return the checksum value. Don’t worry about the code in PHP script.

A: 

You'll need the generation script to echo the return value somewhere in you HTML, then you can use javascript to carry out whatever actions with that value. The only other way is to make an ajax request.

Babiker
A: 

You have three options:

  1. Call the PHP function to generate the checksum within the PHP that generates the page that contains the hyperlink.

  2. If you control purchase.do (unlikely, I know), and requirements allow, find a way to generate the checksum after processing the rest of the arguments (do not pass the checksum initially).

  3. Create an asynchronous request and handler on the client-side to make a call to your php-function onclick, then pass the subsequent request to purchase.do including the resulting checksum value.

tehblanx
A: 

You can call PHP functions anywhere in your file before file is loaded:

<a href="<...>&checksum=<?php echo function_that_generates_checksum(); ?><...>"

If this simple method is not suitable for you, you can try fallowing.

Create a php script redirect.php or similar. Place code similar to this in it:

<?php

$_GET['checksum'] = php_function_to_get_checksum();

header('Location: '
      .'https://secure.gate2shop.com/ppp/purchase.do?'
      .http_build_query($_GET)
      );

In your HTML, change:

<a href="https://secure.gate2shop.com/ppp/purchase.do?&lt;...&gt;

To:

<a href="redirect.php?<...>

Remove the &checksum= variable in this url, you will set that variable in your PHP script which will redirect user to correct url. And you no longer will need onclick.

Skirmantas
what does http_buld_query($_GET) mean.also tell me if i want to buld the complete url in php but not in html then how would i need to proceed
sumit
i need to get all the parameters in php code itself.in html code i just want to pass <a href="redirect.php? while all other parameters after that will be called in php code
sumit
do i need to call it like this <a href="redirect.php?<...> if i m just calling redirect.php and not passing any parameter value..i want that like checksum value all other values should be retrieved in the php function
sumit
you will have all your passed values in redirect.php. You can access them through $_GET['something'] variable. html_build_query() will create an url comfortable string from array. Pass all your values through GET, in PHP add an additional variable: `checksum` to your $_GET variable. And then html_build_query creates a nice url.
Skirmantas