HTML's stateless world

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
mikeb
Forum Commoner
Posts: 60
Joined: Tue Jul 08, 2003 4:37 pm
Location: Dublin, Ireland

HTML's stateless world

Post by mikeb »

Hi,

This question concerns HTML's statelessness and using php to get and act on a response from a remote server.

I'm designing a form which will post to a remote database not under my control. The fields will be posted after a form has been filled. There are a number of 'status' messages supplied by the remote server as to whether or not the posting was successful, such as 'limit of postings exceeded', 'Success', 'Invalid field' etc. I can of course pre-check the form for field validation so that no incorrect data is sent, but some of the errors are not possible to check from the client side. The idea of the error messages are that the user can then act appropriately in response to the message. I would like to automate this response.

My question is:
Because http is stateless, is it possible to trap the error messages/responses from the remote server and use them in my code to make a predetermined reaction to the error programmatically. For instance if the server reports 'Error - 123, Number of allowed posts exceeded' , can I get at this information from the client side? I suppose it would be like reacting to a standard 404 error and interpreting that in my php script. Do I need to involve session variables etc.? Not looking for script, just a point in the right direction :-)
teniosoft
Forum Newbie
Posts: 15
Joined: Tue Feb 03, 2004 1:01 am
Location: Portland, Or

Post by teniosoft »

If you can not predetermine what the response from the database server will be (which you can't) then you can not have everything happen on the client side.

A few other things

HTML is just a way of describing things it has no computational power
javascript and vbscript do have power to compute.

I personally preffer not to put too much stuff on the client side maybe a little validation (like making sure all of the fields are filled in with proper values)

And the on the server you can go and get the response from the database and the forward the user to a specified page based upon that result.

header("location : response404.php");

or possibly better have on page echo the response of the database system
Unipus
Forum Contributor
Posts: 409
Joined: Tue Aug 26, 2003 2:06 pm
Location: Los Angeles, CA

Post by Unipus »

Why don't you know what the server messages are going to be?
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

I don't see the problem here.

[client] - (submit form) -> [script] -> (submit to real server) -> [server]

<- (give customized results) <- <- (output result page) <-
mikeb
Forum Commoner
Posts: 60
Joined: Tue Jul 08, 2003 4:37 pm
Location: Dublin, Ireland

Post by mikeb »

Ok. It's been a while since I sent this request and I think judging be the answers I didn't explain it well.

I have a client who is a recruitment company

they are syndicating jobs to a third part site. I have already coded an XML feed from the site for one such syndicating company and this works fine. The xml feed can be used by them to draw jobs from the main site database.

There is another company who have a different set up. They want my client to post jobs to them rather than go in and collect them automatically via xml. That's simple enough - I build a checkbox on the existing input form which says 'Send job to xyz site?'. They click the checkbox and the job record gets posted to the third party as well as their database.

But here's the problem. Let's say the person posting the job doesn't know that someone else posted the job already? When the job is posted, the third party site will produce an error code 'job already exists'. Is there a way I can use *that* error code and act on it back at my client's site?
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

When you say you are submitting this information to the other server, are you submitting this information via the browser, or are you taking the information entered, and using something like CURL to to the POST for you?

If you are using something like CURL (or basically, you are programming your own HTTP Post), then you simply read the results back, and then can act on them like you would any error message. Report the error the user, and allow them to make the necessary corrections.
mikeb
Forum Commoner
Posts: 60
Joined: Tue Jul 08, 2003 4:37 pm
Location: Dublin, Ireland

Post by mikeb »

your own HTTP Post), then you simply read the results back, and then can act on them like you would any error message. Report the error the user, and allow them to make the necessary corrections.
This is pretty much what I'm doing. I'm beginning to feel a bit stupid here, 'cause I have that feeling that what I'm asking is trivially simple but I'm just not GETTING it :oops: Anyway, I'm Posting the data via http - a standard form post. Are you saying I can get at the error message some way? Is it a bit like trapping a 404 or 500 error from the server? (remember that I don't have access to the remote server, only to the client code). These codes will be generated by the receiving cgi on the remote server, but how do I get the responses in a way that I can use on my end?
Post Reply