Jump to content

Redirection based on server sent url


JStefan

Recommended Posts

Hi all,

I am trying to setup a credit card payment facility for a web site . This will send the user to the gateway company page.

I am sending all the required fields to them with a form with Get method and I get back the following:

<TransactionRequest><Result>True</Result><URI>web link/URI><Error></Error></TransactionRequest> The content of the result and uri tags displays on the page.

If I paste the content of the <URI></URI> tag in the browser all works fine as is supposed to.

My question is: How I can get the content of the <URI> tag into a php variable and redirect my browser to it? Using get_headers maybe?

Thanks in advance for your help,

Julian

Link to comment
Share on other sites

How I can get the content of the <URI> tag into a php variable and redirect my browser to it?

The code I gave you does that. Please be more clear about what you want to do. Post us your code.

 

Hi again, thanks very much for your help.

Here is the code including the one from you. The  $display_block is echoed in the html under the php code, i didn`t paste the html here  :

<?

//session_start();

if(isset($_GET['submit1'])){

//here is your code

preg_match('/<URI>(.*)?<\/URI>/', $response_string, $match);

    header(sprintf("location: %s, $match[0]"));

}

 

else{

$dollars = $_POST["Amount"];

$display_block = "<p><form method=\"GET\" action=\"https://nz.ewaygateway.com/Request\">

<input type=\"hidden\" name=\"CustomerID\" value=\"87654321\">

<input type=\"hidden\" name=\"UserName\" value=\"TestAccount\">

<input type=\"hidden\" name=\"Amount\" value=$dollars>

<input type=\"hidden\" name=\"Currency\" value=\"NZD\">

<input type=\"hidden\" name=\"ReturnURL\" value=\"http://budgetvending.onlinewebshop.net/index.php\">

<input type=\"hidden\" name=\"CancelURL\" value=\"http://budgetvending.onlinewebshop.net/index.php\">

<input type=\"submit\" name=\"submit1\" value=\"Pay Now\"></form>";

 

    }

?>

here is the server answer:

<TransactionRequest><Result>True</Result><URI>https://nz.ewaygateway.com/NZ/PaymentPage.aspx?value=YS8uRaNLlaFaeRReXYncV3thl2bJcYGWU7hoaUAa0sWsFUoyR6</URI><Error></Error></TransactionRequest>

If i copy paste the link in my browser I will get to the right page.

Cheers,

Julian

Link to comment
Share on other sites

Hm ok.

 

So the problem is that you see the response in the browser, while you need it in a string so you can redirect to it with PHP. Right? I think curl will be a good solution here. So instead of a form, you simulate the get request with CURL. Then you get the response in a string and then you can apply my code. Something like:

 

<?php
$ch = curl_init(); 

# Fill out your form parameters in the string below
$queryStr = sprintf(
"?CustomerID=%s&UserName=%s&Amount=%s&etc=%s&etc=%s"
$CustomerID,
$UserName,
$Amount,
$etc,
$etc
);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://nz.ewaygateway.com/Request/" . $queryStr);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);

preg_match('/<URI>(.*)?<\/URI>/', $response, $match);
header(sprintf("location: %s, $match[0]));

?>

 

Link to comment
Share on other sites

Hi,

My code now looks like this:

//session_start();

if(isset($_GET['submit1'])){

 

$ch = curl_init();

 

# Fill out your form parameters in the string below

$queryStr = sprintf(

"?CustomerID='87654321&UserName=TestAccount&Amount=10"

$CustomerID,

$UserName,

$Amount,

 

);

 

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://nz.ewaygateway.com/Request/" . $queryStr);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$response = curl_exec($ch);

curl_close($ch);

 

preg_match('/<URI>(.*)?<\/URI>/', $response, $match);

header(sprintf("location: %s, $match[0]));

}

 

else{

$dollars = $_POST["Amount"];

$display_block = "<p><form method=\"GET\" action=\"https://nz.ewaygateway.com/Request\">

<input type=\"hidden\" name=\"CustomerID\" value=\"87654321\">

<input type=\"hidden\" name=\"UserName\" value=\"TestAccount\">

<input type=\"hidden\" name=\"Amount\" value=\"10\">

<input type=\"hidden\" name=\"Currency\" value=\"NZD\">

<input type=\"hidden\" name=\"ReturnURL\" value=\"http://budgetvending.onlinewebshop.net/index.php\">

<input type=\"hidden\" name=\"CancelURL\" value=\"http://budgetvending.onlinewebshop.net/index.php\">

<input type=\"submit\" name=\"submit1\" value=\"Pay Now\"></form>";

 

    }

?>

 

I get the following error:

Parse error: syntax error, unexpected T_VARIABLE in /home/www/budgetvending.onlinewebshop.net/checkout.php  on line 10

this will be this line : $CustomerID,

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.