form post and http response code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
PapiSolo
Forum Newbie
Posts: 24
Joined: Wed Aug 09, 2006 12:16 pm

form post and http response code

Post by PapiSolo »

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.
Rovas
Forum Contributor
Posts: 272
Joined: Mon Aug 21, 2006 7:09 am
Location: Romania

Post by Rovas »

PapiSolo
Forum Newbie
Posts: 24
Joined: Wed Aug 09, 2006 12:16 pm

Post by PapiSolo »

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.
PapiSolo
Forum Newbie
Posts: 24
Joined: Wed Aug 09, 2006 12:16 pm

Post by PapiSolo »

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?
PapiSolo
Forum Newbie
Posts: 24
Joined: Wed Aug 09, 2006 12:16 pm

Post by PapiSolo »

Found something better here using curl.
Post Reply