Re: Program to Submit to forms [message #173922 is a reply to message #173918] |
Thu, 12 May 2011 22:58 |
Denis McMahon
Messages: 634 Registered: September 2010
Karma:
|
Senior Member |
|
|
On Thu, 12 May 2011 12:43:18 -0700, Charlie wrote:
> [crap]
First you could populate an array with your arbitrary list of websites.
Then you could populate another array with your formdata.
Finally, you could step over the list of websites in a loop and send each
one your formdata.
If you just want to use all the fields in your starter form, you could
just use the post array, but I'm guessing one field in your starter form
will be the list of urls to submit to, perhaps separated by commas, tabs,
carriage returns, spaces or semi-colons, so maybe, given that such a list
might be in a field declared as:
<textarea name="websites" cols="50" rows="10"></textarea>
then you could extract a list of websites with something like (untested
code):
<?php
$urlList = preg_split("/[\s,;]+/",$_POST['websites']);
?>
I would provide a link to the php.net manual page for preg_split, but you
don't like me doing that, so you'll have to search for it yourself.
Now, assuming you want all the other fields in the post data to be posted
as-is to the urls in the list, you might decide to copy them into a new
array:
<?php
$postData = array();
foreach ($_POST as $field => $data) {
if ($field != "websites") $postdata[$field] = $data;
}
?>
Or you could just:
<?php
unset($_POST['websites']);
?>
and use $_POST later on instead of $postData ....
Actually, assuming none of the target websites expects a field called
websites, you probably don't even need to unset it.
Now, presumably you want to post the $postData to all the urls in
$urlList:
<?php
foreach ($url_list as $url) {
// create a curl object
// set the curl url to $url
// set the curl post data option to $post_data
// set other curl (I don't know what settings you need)
// exec the curl request
// handle the result / response somehow
// unset the curl object
}
?>
I couldn't be bothered to look up all the curl function names, you'll
have to do that yourself. I would provide a link to the php.net curl
manual page, but that was "unhelpful" last time I did it.
Oh, and this will only work if your seed form and all your target urls
use the same field names for each field, otherwise your target urls will
get a post data with a load of field names which they'll probably just
ignore.
Rgds
Denis McMahon
|
|
|