Hi all,
Beeing a newbie php programmer, I need some help here.
The scenario
I have a form to gather some user input which is then sent to a remote url via post method. The remote url then returns a http response code indicating either error or all is ok and a file to donwload.
I have no access to the server on the remote end. All I know are the respective http response codes.
What I need
I would like to send the info via post, wait for the response code, and then act on the response code. If there is an error, redisplay the form in order to correct the error. If all is ok, then display a summary of the info and the user will then download the file.
How could I go about doing this. I already have the form and validation is ok, it's just that when I send the info and get an error message, I have to press the back button of the browser.
Any help or pointers in the right direction would be greatly appreciated.
Cheers,
P.
form post and http response code
Moderator: General Moderators
You can use some scripts that' s already made:
http://www.hotscripts.com/PHP/Scripts_a ... index.html
or here
http://lists.evolt.org/archive/Week-of- ... 69427.html
http://www.hotscripts.com/PHP/Scripts_a ... index.html
or here
http://lists.evolt.org/archive/Week-of- ... 69427.html
Thanks for the quick reply Rovas. Unfortunately, it will not help. I think my question came out wrong.
I don't need to handle the download, since that part is handled by the emote server (remote url). If all is correct, they send the file to download.
All I need is a pointer on how to do the following:
Say the gathered info is sent and all is ok, I get a http response code 200, a summary of info stored at the remote server and a file to download (download starts automatically).
If however I get a diferent http response, say a 401, the I have to redisplay the form with an aditional filed to be filled out.
I'm sure there is some way of doing this with ajax and php. All I need is a pointer in the right direction. Then I can learn and post back any dificulties.
I don't need to handle the download, since that part is handled by the emote server (remote url). If all is correct, they send the file to download.
All I need is a pointer on how to do the following:
Say the gathered info is sent and all is ok, I get a http response code 200, a summary of info stored at the remote server and a file to download (download starts automatically).
If however I get a diferent http response, say a 401, the I have to redisplay the form with an aditional filed to be filled out.
I'm sure there is some way of doing this with ajax and php. All I need is a pointer in the right direction. Then I can learn and post back any dificulties.
I've been searching and would like some feedback on this ideia.
The remote url is xepecting something along the line of:
http://remote.url/?id=1234&username=John&some=otherData.....
This will return the above mentioned http response codeswhen the remote server validaes the info.
Could I do something along the lines of:
From: PHP manual
string http_post_data ( string $url [, string $data [, array $options [, array &$info]]] )
Where I would have in my case (that is if I understood this correctly)
$url = http://remote.url/;
$data = ?id=1234&username=John&some=otherData.....;
$reply = http_post_data($url,$data,&$info);
$response = $reply[response_code];
if ($ response == "something"){ do something;}
else{dos something else;}
Is this thinking correct?
The remote url is xepecting something along the line of:
http://remote.url/?id=1234&username=John&some=otherData.....
This will return the above mentioned http response codeswhen the remote server validaes the info.
Could I do something along the lines of:
From: PHP manual
string http_post_data ( string $url [, string $data [, array $options [, array &$info]]] )
Where I would have in my case (that is if I understood this correctly)
$url = http://remote.url/;
$data = ?id=1234&username=John&some=otherData.....;
$reply = http_post_data($url,$data,&$info);
$response = $reply[response_code];
if ($ response == "something"){ do something;}
else{dos something else;}
Is this thinking correct?