Thread: PHP cURL form submission again in trouble
i trying last 2 days. have used curl submit forms pages, time different , difficult. page submitting has 8 hidden fields. did it, first open page, parse fields , submit login form target address. not working...
target log in site http://livearchive.onlinejudge.org/, made page simple form like, page named "la_submit.php"
then in la_process.php, have done follows, (well, there unused codes, please ignore them, file upload part, have copied other simpler application)php code:<html><body>
<form action="la_process.php" method="post" enctype="multipart/form-data">
username: <input name="username" type="text" maxlength="20" />
password: <input name="password" type="password" maxlength="20" />
<input name="submit" type="submit" value="log in" />
</form>
</body></html>
i response login failed. "please log in or register view or modify profile. ", can tell me please, what's wrong here...php code:<?php
if(isset($_post['submit'])===true) {
extract($_post);
if($_files['srcefile']['error'] == 0) {
// a file has been uploaded
$temp = $_files['srcefile']['tmp_name'];
$name = 'upload/'.basename($temp);
move_uploaded_file($temp, $name);
$fp = fopen($name, 'r');
$srcecode = fread($fp, filesize($name));
fclose($fp);
}
}
else { header('location: la_submit.php'); }
$cookie_fname = realpath('cookie').'/'.md5($username . $password . rand(0, 2147483647));
echo '<style type="text/css">pre { padding-left:20px; }</style>';
echo '<hr/><pre>cookie filename:<br/>'.$cookie_fname.'</pre>';
$ch = curl_init();
curl_setopt($ch, curlopt_cookiejar, $cookie_fname);
curl_setopt($ch, curlopt_url,"http://livearchive.onlinejudge.org/");
curl_setopt($ch, curlopt_returntransfer, 1);
$page = curl_exec($ch);
$info = curl_getinfo($ch);
$loginform = '!';
$data['username'] = $username;
$data['passwd'] = $password;
if(preg_match_all('/<form(.*)>(.*)<\/form>/smu', $page, $matches)) {
foreach($matches[0] as &$value) {
if(preg_match('/id="mod_loginform"/', $value)) {
$loginform = $value;
echo '<hr/><pre>'.htmlspecialchars($loginform).'</pre>';
preg_match_all('/<input.+type="hidden"(.*)>/', $loginform, $hidden);
foreach($hidden[0] as &$field) {
echo '<hr/><pre>'.htmlspecialchars($field).'<br/>';
preg_match('/name="[^\s]*"/', $field, $field_name);
preg_match('/value="[^\s]*"/', $field, $field_value);
$tmp1 = preg_replace('/name="(.*)"/', '$1', $field_name[0]);
$tmp2 = preg_replace('/value="(.*)"/', '$1', $field_value[0]);
echo '['.$tmp1.']['.$tmp2.']</pre>';
$data[$tmp1] = $tmp2;
}
break;
}
}
}
$data['submit'] = 'login';
if($loginform == '!') { header('location: la_submit.php'); }
echo '<hr/><pre>';
foreach($data as $tmp1 => $tmp2) {
echo '['.$tmp1.']['.$tmp2.']<br/>';
}
echo '</pre>';
$post_url = '';
foreach($data as $key => $value)
$post_url .= $key.'='.rawurlencode($value).'&';
$post_url = rtrim($post_url, '&');
echo '<hr/><pre>'.$post_url.'</pre>';
curl_setopt($ch, curlopt_cookiefile, $cookie_fname);
curl_setopt($ch, curlopt_url,"http://livearchive.onlinejudge.org/index.php?option=com_comprofiler&task=login");
curl_setopt($ch, curlopt_post, 1);
curl_setopt($ch, curlopt_postfields, $post_url);
curl_setopt($ch, curlopt_returntransfer, 1);
$page = curl_exec($ch);
$info = curl_getinfo($ch);
echo '<hr/>'.$page. '<hr/>curl status: ';
print_r($info);
?>
so, how can log in here? please me
information, if try test on localhost / server, need make 2 folders named "upload" , "cookie" write permission user.
sorry bump, use![]()
Forum The Ubuntu Forum Community Ubuntu Specialised Support Development & Programming Programming Talk [SOLVED] PHP cURL form submission again in trouble
Ubuntu
Comments
Post a Comment