I do have an html form that accepts textbox input of sha1 hashes per line:
<textarea id="mid "name="mid" cols="40" rows="5"></textarea>
Example values are:
9a3845cf0aac825d4e754610baa473f53636f10a
9a3845cf0aac825d4e754610baa473f53636f10b
9a3845cf0aac825d4e754610baa473f53636f10c
My problem is I need to take each value from the textbox "per line" and pass it to curl, my code below works only on a single entry basis:
<?php
$pf="pf";
$ur="ur";
$pw="pw";
$url="url.com";
extract($_POST);
$mid=$_POST['mid'];
$fields = array(
'user'=>urlencode($ur),
'pass'=>urlencode($pw),
'pfid'=>urlencode($pf),
'msid'=>urlencode($mid)
);
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string,'&');
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
$result=curl_exec($ch);
curl_close($ch);
?>
My expected output from the curl'ed server are the results of all those from the textbox:
9a3845cf0aac825d4e754610baa473f53636f10a - okay
9a3845cf0aac825d4e754610baa473f53636f10b - cancelled
9a3845cf0aac825d4e754610baa473f53636f10c - okay
Any thoughts? Thanks in advance!
explode
on the new line character:
$mids = explode("
", $mid);
Then you can access each line:
foreach ($mids as $mid){
// ... etc
Thanks. It worked. This is what I did from the actual code:
<?php
$pf="pf";
$ur="ur";
$pw="pw";
$url="url.com";
extract($_POST);
$mid=$_POST['mid'];
$mids = explode("
", $mid);
foreach ($mids as $mid){
$fields = array(
'user'=>urlencode($ur),
'pass'=>urlencode($pw),
'pfid'=>urlencode($pf),
'msid'=>urlencode($mid)
);
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string,'&');
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
$result=curl_exec($ch);
curl_close($ch);
}
?>
I now have an output. My only issue is that pre-formatting it. I am actually expecting an output of four (4) fields and lines = x. Curently I'm getting the output as:
ID: 947c5d5982bf1a83020bca6c330fe94f
Stat: OKID: c9218019acde8ff547779c4ecd77f8f4
Stat: OKID: 47f2c7d65a9c3cccda3a9eb7497dbeee Stat: OK
Instead of the correct one
ID: 947c5d5982bf1a83020bca6c330fe94f Stat: OK
ID: c9218019acde8ff547779c4ecd77f8f4 Stat: OK
ID: 47f2c7d65a9c3cccda3a9eb7497dbeee Stat: OK
Is there a sample for this? Should I use explode to fix the formatting. Thanks again.