Curl 和 javascript 提交
我尝试使用 javascript 提交过程来卷曲页面,但没有任何运气......所以我向社区寻求一些帮助!
这是表单:
<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>
我的curl函数:
{
/**
* 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;
}
感谢您的输入,上面的代码没有验证表单,我想我错过了提交验证过程的一些内容......
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...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您需要调用 vallogin() 函数?
我在您的代码中没有看到提交按钮,因此类似:
可能有效。
不过,使用 JQuery 和 AJAX 进行发布然后返回结果可能是更好的选择。
http://api.jquery.com/jQuery.post/
或者它可能是你需要的表单属性中的 onsubmit="vallogin()" 。
I think you need to call the vallogin() function?
I don't see a submit button in your code, so something like:
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.
如果您需要的只是发布表单 @logic-unit 具有
在您的 php 代码上执行页面的正确方法,那么您似乎做得很好,只需确保您确定何时调用
函数
只是确保你不会混淆 GET 和 POST,你似乎正在传递用户、密码数据,这些数据应该位于 php 的 _POST 对象上,或者你甚至可以考虑使用 _REQUEST
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
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