tags:

views:

247

answers:

2

I have a form page in PHP that reads a DBF, and conditionally converts it into a MySQL - extracting the data from an old, but still production accounting app. The conversion should be able to be actioned without user intervention, ie scripted from the web-host's command line on a cron job.

How can I get PHP to submit the form automatically when receiving variables at command line, like for instance a specific post variable? Every auto-submit I've found so far relied upon javascript, which would be useless at PHP command line.

+1  A: 

If I understand you correctly, you are trying to pass data to a PHP script automatically that used to be passed through a HTML form. When automating this process in a cron job, no form is rendered so auto-submitting it is out of the question - you will usually pass the data to the script straight away.

Methods to do that include:

  • If your form data is tiny (less than 1k, no file uploads) then you could call the script from the cron job, but still through the web server, using wget or curl:

    curl www.example.com/script.php?field1=value1&field2=value2&field3=value3
    
  • If your form data is more than 1-2 kilobytes, use curl to pass the fields as POST values (see the manual on curl)

  • Call the PHP script from the command line using the PHP binary; pass the data as arguments to the script. Details here

  • If the data is too much to be passed through the command line, put it into a temporary file and have your PHP script parse that.

Pekka
Thanks, you confirmed my suspicions. Yes, I want the command line to work, but for the same form to also work as it does for user direct interaction in the browser. The data is hefty...around 5mb for the page load of html, as there are over 6000 items listed. So I think I will have to go for your last option...and for the condition of command line, write to another file, then have the receiving script search for and parse that file if existing. Cheers :D
@combatwombat no problem. If you want the HTML form to continue to work with the same script, consider the second option. With curl, you can even upload files as you would in a HTML form. It's the best solution if you want to leave the receiving script untouched.
Pekka
A: 

You can write a cli script in almost any language that supports making GET/POST requests (PHP, Python, Bash with curl, Java...) and perform the same call as submitting form will do...

Supose a form with 2 textfields: foo and bar

There is 2 major cases:

maid450