I've created a mod for processing information posted by a return function from an online payment site. After It processes the information It must post some variables to another mod. I'm just starting in PHP programming and cant find a way for doing that without creating a form and forcing the user to click on a button.
Let's say my mod is called return.php and receives a number of posted fields from the payment link return function. This mod processes that information and creates two variables called $_ord_id (string) and $_purchased (yes/no).
After processing that infromation it must automaticaly redirect to a URL like http://mysite.com/mod.php?mod=orders&mode=return posting those two variables to the URL.
Now the question: What would be the code to do that redirection and post those variables?
Thanks for the help.
Airton
7 1764
Welcome to The Scripts!
You show a lot of text, but where is your code? If you want us to help you, show the code you have developed so far and we will have a look and try to see what you need to achieve your goal.
Ronald :cool:
the solution can be simple if you use a session.
[PHP]
if(count($_POST) > 0){
// process the form
// put variables in the session
$_SESSION['ord_id'] = $_ord_id;
$_SESSION['purchased'] = $_purchased;
// redirect to other page
header('http://mysite.com/mod.php?mod=orders&mode=return');
}
[/PHP]
If you do this it's best you include these pages in a master page and you start the session there. For security reasons you can unset the session variables when you finished processing them on the redirected page.
Sorry guys for not having posted my code. But now, here it goes:
Whem my client finishes the payment process at the on-line payment site it will return automaticaly to this script by calling the URL http://mysite.com/return.php and posting a number of values to it.
[PHP]// RECEIVES THE POST SENT BY BRPAY AND VALIDATE THE DATA
$BRpay = 'Comando=validar';
$BRpay .= '&Token=1234567890';
$Cabecalho = "";
foreach ($_POST as $key => $value){
$value = urlencode(stripslashes($value));
$BRpay .= "&$key=$value";
}
if (function_exists('curl_exec')){
$curl = true;
}
elseif ( (PHP_VERSION >= 4.3) && ($fp = @fsockopen('ssl://www.brpay.com.br', 443, $errno, $errstr, 30)) ){
$fsocket = true;
}
elseif ($fp = @fsockopen('www.brpay.com.br', 80, $errno, $errstr, 30)){
$fsocket = true;
}
// SEND DATA BACK TO BRPAY FOR VALIDATION
if ($curl == true){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.brpay.com.br/Security/NPI/Default.aspx/');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $BRpay);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$resp = curl_exec($ch);
if (!tep_not_null($resp)){
curl_setopt($ch, CURLOPT_URL, 'http://www.brpay.com.br/Security/NPI/Default.aspx/');
$resp = curl_exec($ch);
}
curl_close($ch);
$confirma = (strcmp ($resp, "VERIFICADO") == 0);
}
elseif ($fsocket == true){
$Cabecalho = "POST /Security/NPI/Default.aspx HTTP/1.0\r\n";
$Cabecalho .= "Content-Type: application/x-www-form-urlencoded\r\n";
$Cabecalho .= "Content-Length: " . strlen($BRpay) . "\r\n\r\n";
if ($fp || $errno>0){
fputs ($fp, $Cabecalho . $BRpay);
$confirma = false;
$resp = '';
while (!feof($fp)){
$res = @fgets ($fp, 1024);
$resp .= $res;
// Verifies if the transaction status is VERIFICADO (VERIFIED)
if (strcmp ($res, "VERIFICADO") == 0){
confirma=true;
break;
}
}
fclose ($fp);
}
}
if (confirma){
$_purchased = 'yes';
}
else{
$_purchased = 'no';
}[/PHP]
At this point the script will process the posted fields and may or may not change the $_purchased value depending on the results (under development). The value for $_ord_id is also posted to this script.
After the processing the script must redirect to http://mysite.com/mod.php?mod=orders&mode=return posting $_purchased and $_ord_id to that URL. This is the part of the code that I need.
All the user interaction is done by this last URL.
Thanks for the help so far.
Airton
I've made some changes to my script and it's not working. I tried to use xwero's sugestion bu all I get is a blank page when the pay-link returns to my mod and it doesn't redirects to the URL it should. What coud be wrong?
Thanks for the help.
Airton
Here is the modified code:
[PHP]<?php
// RECEBE O POST ENVIADO PELA BRPAY E ADICIONA OS VALORES PARA VALIDAÇÃO DOS DADOS
$BRpay = 'Comando=validar';
$BRpay .= '&Token=123456789';
$Header = '';
$confirma = false;
foreach ($_POST as $key => $value){
$value = urlencode(stripslashes($value));
$BRpay .= "&$key=$value";
}
if ( (PHP_VERSION >= 4.3) && ($fp = @fsockopen ('ssl://www.brpay.com.br', 443, $errno, $errstr, 30)) ){
$fsocket = true;
}
elseif ($fp = @fsockopen('www.brpay.com.br', 80, $errno, $errstr, 30)){
$fsocket = true;
}
// ENVIA DE VOLTA PARA A BRPAY OS DADOS PARA VALIDAÇÃO
if ($fsocket == true){
$Header = "POST /Security/NPI/Default.aspx HTTP/1.0\r\n";
$Header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$Header .= "Content-Length: " . strlen($BRpay) . "\r\n\r\n";
if ($fp || $errno>0){
fputs ($fp, $Header . $BRpay);
$resp = '';
while (!feof($fp)){
$res = @fgets ($fp, 1024);
$resp .= $res;
if (strcmp ($res, "VERIFICADO") == 0){
$confirma=true;
break;
}
}
fclose ($fp);
}
}
$_ord_id= $_POST['Referencia'];
if ($Confirma){
$_Status = 'OK';
}
else{
$_Status = 'NOK';
}
// REDIRECIONA PARA A FUNCAO DE RETORNO
$_SESSION['ord_id'] = $_ord_id;
$_SESSION['Status'] = $_Status;
// redirect to other page
header('http://www.hotspothosting.com.br/mod.php?mod=orders&mode=return');
?>[/PHP]
Where did you start your session?
For the session option to work you need to embed the page you got in a master page which handles the redirections. And in that page you start your session so you can get and set session variables for all the pages that are embedded.
a quick an dirty redirection masterpage example
[PHP]
// cache get variables for checking
$getParameter1 = $_GET['parameter1'];
// checking code here
// page redirection based on first parameter
switch($getParameter1){
case 'a':
// cache get variables after first parameter for checking
$getParameter1_1 = $_GET['parameter1_1'];
// checking code here
// page redirection
include('page1.php')
break;
}
[/PHP]
if that page is named index.php all the urls are index.php?... The url to get you to page1.php is index.php?parameter1=a¶meter1_1=b.
You can have as many levels as you want ofcourse.
[PHP]<?php
header('http://www.hotspothosting.com.br/mod.php?mod=orders&mode=return');
?>[/PHP]
should be
[PHP]<?php
header('Location: http://www.hotspothosting.com.br/mod.php?mod=orders&mode=return');
?>[/PHP]
Thank you guys for your help.
Talking to the developer of my shoping cart I got to know that I could use GET to pass the values to the mod, so I changed the last part of my code (based on the tips from xwero) as follows:
[PHP]$_ord_id= $_POST['Referencia'];
if ($Confirma){
$_Status = 'OK';
}
else{
$_Status = 'NOK';
}
// REDIRECTS TO phpCoin RETURN FUNCTION
$Header = 'Location: http://www.hotspothosting.com.br/mod.php?mod=orders&mode=return&ord_id=';
$Header .= $_ord_id;
$Header .= '&Status=';
$Header .= $_Status;
// redirect to other page
header($Header);
[/PHP]
Now it's working as expected.
Thanks again.
Cheers :)
Airton
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Mike |
last post by:
I'm used to unix/cgi scripts so im slightly out of my depth here.
Ive got an asp script for a website form which works fine.
What i want to do is also get the form to include the ip address of the...
|
by: Surendra |
last post by:
I have this query that I need to use in an Update statement to
populate a field in the table by the value of Sq
----------------------------------------------------------------------------
Inline...
|
by: vbmax |
last post by:
Hi to all!
I have to write the following program.
1.User inputs a number (example: 5)
2.Then (because he entered 5) he enters 5 times, each time different,
3-placed number (example: 134, 256,...
|
by: worzel |
last post by:
Hi All,
I am looking for a reg ex that will match email addresses withing <a
href=mailto blah > links.
Actually, I already crafted my own, but with a slight problem:
<a...
|
by: Jeremy Weiss |
last post by:
I'm trying to build a database that will handle the monthly billing needs of
a small company. I'm charting everything out and here's what I see:
table for customers
sub table to track payments...
|
by: Timothy Shih |
last post by:
Hi, I am trying to figure out how to use unmanaged code using P/Invoke. I
wrote a simple function which takes in 2 buffers (one a byte buffer, one a
char buffer) and copies the contents of the byte...
|
by: Jason |
last post by:
Hi,
I was wondering if any could point me to an example or give me ideas on how
to dynamically create a form based on a database table? So, I would have a
table designed to tell my application...
|
by: gunimpi |
last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431
********************************************************
VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help
wanted...
|
by: Tom |
last post by:
First, I posted a similar request for help in another group and now
don't find the posting. Problem with my newsreader perhaps ... but
apologies if this appears as a cross posting.
My code is...
|
by: tracy |
last post by:
Hi, I really need help.
I run this script and error message appeal as below:
drop trigger log_errors_trig;
drop trigger log_errors_trig
ERROR at line 1:
ORA04080: trigger 'LOG_ERRORS-TRIG'...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |