I'm pretty new to this so not really too sure what's wrong so don't know how to describe the problem. But...basically what I'm attempting to do is login to a particular website and then submit a form that's on a second page.
I've managed to do this fine with loads of other sites, but this for some reason is giving some trouble.
The login form:
...and the code I'm using to submit the login form...
...which seems to work just fine and get me logged in.
The next part is what I'm having trouble with.
The form to submit (with all the shit cleaned out of it):
...and the code I'm trying to submit it using...
I've submitted to form manually and watched the output from Live HTTP Headers and afaik I've got everything in there.
Can anybody see any potential problems with it that could be causing it to not work?
I've managed to do this fine with loads of other sites, but this for some reason is giving some trouble.
The login form:
Code:
<form action="/lo/index.php" method="POST" enctype="multipart/form-data">
<table width="350" border="1" style="border-collapse: collapse" bordercolor="#5e74b3">
<tr>
<td align="center" class="ff">
<img src="templates/images/key.gif" border="0" width="48" height="48" align="absmiddle">
<span class="sectitle">Administration Entrance</span>
</td>
</tr>
<tr>
<td align="center" style="background: #fef0e5;">
<br>
<span class="ftitle">Password: </span>
<input type="password" name="password" size="15" maxlength="255" value="" class="text">
<Br><br>
<input type="hidden" name="redir" value="">
<input type="hidden" name="processlogin" value="1">
<input type="image" src="templates/images/login.gif" border="0" width="72" height="25" value="Login" class="submit"><br>
<input type="checkbox" name="saveinfo" value="save" checked>Save my info for Auto Login next time</td></tr>
</table>
</form>
Code:
<?php
$lourl = 'http://www.domain.com';
$lopass = 'password';
$cookie = file('/tmp/cookie.txt');
$useragent = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3';
$lologinparameters = array('password' => $lopass, 'processlogin' => '1', 'saveinfo' => 'save');
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_FAILONERROR, TRUE);
curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch, CURLOPT_URL, $lourl . '/lo/index.php');
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $lologinparameters);
$lologin = curl_exec($ch);
curl_close($ch);
echo $linksorganizer;
?>
The next part is what I'm having trouble with.
The form to submit (with all the shit cleaned out of it):
Code:
<form name="myform" action="/lo/index.php" method="POST" enctype="multipart/form-data" onsubmit="select_all_selectlist('sites');">
<input type="text" name="name" value="" size="30" maxlength="255" class="text">
<input type="text" name="email" value="" size="40" maxlength="255" class="text">
<input type="text" name="icq" value="" size="20" maxlength="255" class="text">
<select name="partnerid"><option value='0'>Select Partner</option></select>
<input type="text" name="url" value="" size="50" maxlength="255" class="text">
<input type="text" name="recip_url" value="" size="40" maxlength="255" class="text">
<input type="text" name="abc_recip" value="" size="40" maxlength="255" class="text">
<input type="text" name="anchor" value="" size="50" maxlength="255" class="text">
<input type="text" name="title" value="" size="50" maxlength="255" class="text"> <a href="javascript:void(0);" onclick="copy_anchor()" class='helplink'>Copy from above</a>
<textarea name="descr" cols="50" rows="4"></textarea>
<script>
var sitegrp=new Array();
sitegrp[1]="1||http://www.siteone.com|#|2||http://www.sitetwo.com|#|3||http://www.sitethree.com";
sitegrp[2]="4||http://www.sitefour.com|#|5||http://www.sitefive.com|#|6||http://www.sitesix.com";
</script>
<select name="sitecategories" onchange="display_sites_by_category(this.value);">
<option value='0'>Select Category</option>
<option value='-1'>All Categories</option>
<option value='1'>Category 1</option>
<option value='2'>Category 2</option>
</select>
<select name="tmpfeeds" id="tmpfeeds" multiple style="width:500px;" size="10" onDblClick="copySelectedOptions(document.getElementById('tmpfeeds'),document.getElementById('sites'))"></select>
<select name="sites[]" id="sites" multiple size='10' style="width:500px;" onDblClick="removeSelectedOptions(document.getElementById('sites'))"></select><br>
<a onclick="removeAllOptions(document.getElementById('sites'))">Deassign All</a><br><span class="helptext">(Multiple selection enabled. Hold CTRL and click on desired values)
<select name="status">
<option value='1'>Disabled</option>
<option value='2' selected>Active</option>
</select>
<select name="link_check"><option value='0'>No</option><option value='1' selected>Yes</option></select>
<select name="is_special"><option value='0' selected>No</option><option value='1'>Yes</option></select>
<select name="invisible"><option value='0' selected>No</option><option value='1'>Yes</option></select>
<input type="text" name="exptime" value="0" size="2" maxlength="255" class="text">
<textarea name="comments" cols="60" rows="4"></textarea>
<input type="checkbox" name="check_recip" value="1"> Yes
<input type="hidden" name="addthetrade" value="1">
<input id="submit" type="image" src="templates/images/add.gif" border="0" width="72" height="25" value="Add" class="submit">
</form>
Code:
<?php
$webmastername = 'name';
$webmasteremail = 'name@domain.com';
$webmastericq = '123456789';
$tradeurl = 'http://www.tradeurl.com';
$recipurl = 'http://www.recipurl.com';
$abcrecip = 'http://www.abcrecip.com';
$anchor = 'Anchor Text';
$title = 'Title Text';
$description = 'Description of trade';
$comments = 'Comments about trade';
$addtradeto = '2';
$loaddparameters = array(
'name' => $webmastername,
'email' => $webmasteremail,
'icq' => $webmastericq,
'url' => $tradeurl,
'recip_url' => $recipurl,
'abc_recip' => $abcrecip,
'anchor' => $anchor,
'title' => $title,
'descr' => $description,
'sites[]' => $addtradeto,
'status' => '2',
'link_check' => '1',
'is_special' => '0',
'invisible' => '0',
'exptime' => '0',
'comments' => $comments,
'check_recip' => '0',
'addthetrade' => '1',
'expaction' => '1',
'partnerid' => '0',
'sitecategories' => ''
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch, CURLOPT_URL, $lourl . '/lo/index.php');
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $loaddparameters);
$addlotrade = curl_exec($ch);
curl_close($ch);
?>
Can anybody see any potential problems with it that could be causing it to not work?