PDA

View Full Version : Submit a form (POST) via PHP.



Chris
08-30-2007, 11:52 AM
Here is my problem.

I have this supplier who offers drop shipping, I decided to try to add his entire product catalogue onto my site, both sites use oscommerce too... except...

His company is obviously not very technical savvy, they wouldn't just give me a database dump and say they're working on setting up a web feed for their products. Whatever, if I don't get the products added in the next 30 days I'll miss christmas with them.

So I hired someone to make a php web crawler that'd crawl their site, parse it all, and add the products to my database. It works great.... except... their website requires you login first to see prices. So my database has no prices in it.

I could go in by hand and add them all, but i don't want to, I want an automated solution, and no, they don't have so much as a CSV pricelist.

I tried faking the form by turning it into a GET request (query string) but oscommerce accesses the variables like this:



if (isset($HTTP_GET_VARS['action']) && ($HTTP_GET_VARS['action'] == 'process')) {
$email_address = tep_db_prepare_input($HTTP_POST_VARS['email_address']);

So obviously it needs to be a post request.

So, does anyone know of any way to use php to simulate a post request?

Nico
08-30-2007, 12:25 PM
I didn't quite get what you are trying to do, but you can certainly send a POST request through PHP using CURL: http://www.php.net/manual/en/ref.curl.php

Examples of form submissions with cURL:
http://www.higherpass.com/php/tutorials/Using-Curl-To-Query-Remote-Servers/2/
http://www.shimul.info/archives/php/form-submit-in-different-way

rpanella
08-30-2007, 02:36 PM
The Snoopy php class (http://sourceforge.net/projects/snoopy/) would make this very easy. It is easy to do POST requests and will keep track of cookies and session info to keep you logged in when you crawl the other pages. I've used it before for scripts to login to affiliate networks etc and automatically pull stats for me.

Depending on how complex the crawler is it should be pretty easy to do and only take a couple mins. Let me know if you have any questions or need help.
________
Honda cb750 (http://www.honda-wiki.org/wiki/Honda_CB750)

alien
09-02-2007, 11:12 PM
Use cURL. It's easier and quicker!

Todd W
09-02-2007, 11:39 PM
The Snoopy php class (http://sourceforge.net/projects/snoopy/) would make this very easy. It is easy to do POST requests and will keep track of cookies and session info to keep you logged in when you crawl the other pages. I've used it before for scripts to login to affiliate networks etc and automatically pull stats for me.

Depending on how complex the crawler is it should be pretty easy to do and only take a couple mins. Let me know if you have any questions or need help.

I was going to suggest snoopy class too. Works great.

I was also going to suggest you have your php coder write-up a lil script 50 EASY LINES or less to just grab all the info from their db and e-mail you the txt/csv file ;) (Or output XML to screen in your format)

This way you can just say here's this file upload it to your WWW directory, and you run it :) This way you could easily check/get new products.

I wrote something identical for OSC to create a "1 page" printable catalog for someone.



-Todd

Nico
09-03-2007, 05:36 AM
I never used the Snoopy class before, but after checking their code, i can see that they are using cURL too :) Only that they are not using curl php built in function probably because that class is from 2000 and probably those functions were kind of new to PHP back then.

I would personally choose to use the curl built in functions of PHP.