views:

43

answers:

3

I have a form that collects a user's username and password for a third-party site. Only when the login information works do I want to proceed on my site. My problem is that I currently have it set up as a form with the action link the third-party and when they click on the button, it just redirects them to the other site. How can I only test that the username and password succeeds on the page without sending them to the page? Is there a way with PHP?

+1  A: 

Yes there is -> curl extension or http_post_data() ( or http_post_fields() part of pecl_http extension). There are examples too. Depending on third-party site returned html/cookies/etc proceed the process or draw an error message.

Anpher
A: 

Yes. You have it post the login information to your page first. Your page then curl's (or some other way of getting a remote page, such as http_post_data) that third party page, and checks of the login worked or not. You may also then have to hit that third party page a second time, to log you out (if it preserves the login, that would be bad).

Anyway, after it returns, you can then process the page as a login success or failure.

zebediah49
A: 

This could be done with jQuery, avoiding any server-side complications. You could submit the form via the .post event, and read the response body to see if it was successful or not (they will probably have a success page, perhaps a user home page, or error page).

alecwh