Reputation: 315
I try to curl a page with a javascript submit process with out any luck... So I ask the community for some help!
Here is the form :
<script>
<!--
function vallogin(){
document.formlogin.action = "./index.php?vallogin=1";
document.formlogin.submit();
}
-->
</script>
<form name="formlogin" method="post">
<div class="headerblocgris">
<span class="txtnoir12">| Accès |</span>
</div>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="txtnoir12">Login</td>
<td><input name="txtlogin" type="text" size="15" /></td>
<td><span class="txtnoir12">Password</span></td>
<td>
<input name="txtmdp" type="password" size="15" />
<input type="image" name="vallogin" src="images/bt_go.gif" align="absmiddle" />
</td>
</tr>
</table>
</form>
And my curl function :
{
/**
* Connexion
*/
$URL = 'http://www.affiliatevista.com/index.php?vallogin=1';
$data = array(
'txtlogin' => $this->login,
'txtmdp' => $this->passe,
'formlogin' => '',
'vallogin' => '',
);
curl_setopt($this->ch, CURLOPT_URL, $URL);
curl_setopt($this->ch, CURLOPT_HEADER, true);
curl_setopt($this->ch, CURLOPT_POSTFIELDS, $this->implode_array($data));
curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($this->ch, CURLOPT_COOKIEJAR, $this->_getCookie());
curl_setopt($this->ch, CURLOPT_COOKIEFILE, $this->_getCookie());
curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, true);
$String = curl_exec($this->ch);
echo $String;
}
Thanks for your input, the code above doesn't validate the form, I think I miss something with the submit validation process...
Upvotes: 0
Views: 9843
Reputation: 1272
if all you need is post the form @logic-unit has the proper way of executing the page
on your php code you seem to be doing things ok, just make sure you identify when to call the function
if( isset($_GET['vallogin']) && $_GET['vallogin'] === 1 ){
//execute function here
}
just make sure you dont confuse your GET and your POST, you seem to be passing user, password data, which should be on the _POST object of php, or you might even consider using _REQUEST
Upvotes: 0
Reputation: 4313
I think you need to call the vallogin() function?
I don't see a submit button in your code, so something like:
<input type="submit" value="Login" onclick="vallogin(); return false" />
might work.
Using JQuery and AJAX to do a post then return a result might be a better option though.
http://api.jquery.com/jQuery.post/
Or it could be you need an onsubmit="vallogin()" in your form attributes.
Upvotes: 2