Fireworksable
Fireworksable

Reputation: 343

Continuous MySQL Database Querying in PHP?

I'm looking for the easiest and most sensible way to allow this scenario to occur;

User loads page --> While page is loaded it continuously queries a database until it finds a certain value is set (the users IP address) --> Once that value is set it will redirect the page.

The reason why I can't simply take the users IP on the page, insert it into the database and then redirect is because the IP address is used for a method of validation, and is passed through as a parameter to a seperate website (that I have no control over), then once the user has completed a set of actions on that website it is passed back and added into my database.

If anyone could point me in the write direction, of which PHP functions I could use and such, I would greatly appreciate it :)!

Upvotes: 0

Views: 1091

Answers (1)

deceze
deceze

Reputation: 522005

The best way to keep querying on the original page is probably via AJAX. Send an AJAX request to a script on your server every 20 seconds or so to check whether the database has been updated with the data you're looking for. To make this more realtime, long-polling/Comet is a technique you may want to look into as well.

A very low-tech solution would be a simple page that keeps refreshing itself, checking the database on each load.

Using the IP as the unique identifier is not very granular though. That may give a large range of people blanket access if only one person filled out an offer. Unless that's no problem for you, it'd be better to create a long random string, save it in the session, send it along as the subid and wait for it to come back. That way you can identify a user uniquely. You could even identify specific actions a user took uniquely.

Hope that gets you going.

Upvotes: 2

Related Questions