0

I am learning to POST data to a URL. I want to send some data to the URL everyday automatically. I've read this curl-less and this curl, both seem to be a little complicated for me - that I need to take care of something other than the data itself.

I am thinking maybe I can just use a fake form, hardcode the data into the form and after page loaded, programmatically "click" to submit the form, which should be much easier for me.

Is this doable? Is there any downside? Among the 3 ways, when should I use which one?

2
  • I recommend you to use curl. So you can use cron and set daily periods Commented May 25, 2016 at 15:20
  • that is an issue I haven't brought up yet. Can cron job open a php page or execute some php code? Commented May 25, 2016 at 15:24

1 Answer 1

1

Q: Can cron job open a php page or execute some php code?

A: Yes, you can do nearly everything with cron job

Use cron jobs with curl.

Sample curl POST request

1- Prepare your script

myscript.php

// set post fields
$post = [
    'username' => 'user1',
    'password' => 'passuser1',
    'gender'   => 1,
];

$ch = curl_init('http://www.example.com');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);

// execute!
$response = curl_exec($ch);

// close the connection, release resources used
curl_close($ch);

// do anything you want with your response
var_dump($response);

2- Set your cron

Run your script automatically with cron jobs on your linux environment like this

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. What is the disadvantage of using a fake form?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.