JStefan Posted May 14, 2010 Share Posted May 14, 2010 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 https://forums.phpfreaks.com/topic/201795-redirection-based-on-server-sent-url/ Share on other sites More sharing options...
CodeMaster Posted May 15, 2010 Share Posted May 15, 2010 What about this? <?php preg_match('/<URI>(.*)?<\/URI>/', $response_string, $match); header(sprintf("location: %s", $match[0])); ?> Link to comment https://forums.phpfreaks.com/topic/201795-redirection-based-on-server-sent-url/#findComment-1058887 Share on other sites More sharing options...
JStefan Posted May 16, 2010 Author Share Posted May 16, 2010 Did not work, I still get the XML on browser, but thanks for suggestion Link to comment https://forums.phpfreaks.com/topic/201795-redirection-based-on-server-sent-url/#findComment-1059045 Share on other sites More sharing options...
CodeMaster Posted May 16, 2010 Share Posted May 16, 2010 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. Link to comment https://forums.phpfreaks.com/topic/201795-redirection-based-on-server-sent-url/#findComment-1059060 Share on other sites More sharing options...
JStefan Posted May 17, 2010 Author Share Posted May 17, 2010 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 https://forums.phpfreaks.com/topic/201795-redirection-based-on-server-sent-url/#findComment-1059644 Share on other sites More sharing options...
CodeMaster Posted May 18, 2010 Share Posted May 18, 2010 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 https://forums.phpfreaks.com/topic/201795-redirection-based-on-server-sent-url/#findComment-1059883 Share on other sites More sharing options...
JStefan Posted May 18, 2010 Author Share Posted May 18, 2010 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 https://forums.phpfreaks.com/topic/201795-redirection-based-on-server-sent-url/#findComment-1059973 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.