PDA

Просмотр полной версии : Парсинг формы для гет/пост запроса


rcc0023
17.04.2009, 05:57
Есть ли готовые варианты (с script изменением) для подготовки запроса? То есть есть форма:

<form name=log action='login.php' method=post><input type=hidden name=LOGIN_redirect value=1>

<input name="login" type="text" maxlength=150 class="id" title='Логин в игре'
value=' Имя персонажа' onfocus="clearLogin();">
<input name="pass" class="id2" type="password" maxlength=20 title='Пароль в игре' value='12345678901234567890' onfocus="clearPassw();">
<input type=hidden name="preseted" value=0>
<input type=image name=lbut src='i/index/left_buttons21.jpg' title='Войти в игру!'></form>

<script type="text/javascript"> function clearLogin() { if (log.lreseted.value == 0) { log.login.value= ''; log.lreseted.value = 1; } } function clearPassw() { if (log.preseted.value == 0) { log.pass.value= ''; log.preseted.value = 1; } } </script>


запрос брал так...
$lbutx=rand(1,57); $lbuty=rand(1,17); $game_login_u=rawurlencode($game_login); $game_pass_u=rawurlencode($game_pass); $html=file_get_contents($url.'index.php'); $html=str_replace('"','',$html); $html=str_replace("'",'',$html); $html=str_replace('>',' >',$html); $html_2=str_replace(' ','',$html); $text_01='<input'; $text_1=explode($text_01,$html); $text_2=explode('<form',$html); $text_3=explode('>',$text_2[1]); $text_12=explode('name=',$text_3[0]); $text_13=explode(' ',$text_12[1]); $text_14=explode('action=',$text_3[0]); $text_15=explode(' ',$text_14[1]); $f_forma_name=$text_13[0]; $f_forma_action=$text_15[0]; $no_error_1=substr_count($html,$text_01); while($no_error_1 >= $key){ $html_str2=explode('>',$text_1[$key]); $html_str=$html_str2[0]; $text_4=explode('name=',$html_str); $text_5=explode(' ',$text_4[1]); $text_6=explode('type=',$html_str); $text_7=explode(' ',$text_6[1]); $text_8=explode('value=',$html_str); $text_9=explode(' ',$text_8[1]); $text_10=explode($f_forma_name.'.'.$text_5[0].'.value=',$html_2); $text_11=explode(';',$text_10[2]); $f_name=$text_5[0]; $f_type=$text_7[0]; $f_value=$text_9[0]; $f_java_value=$text_11[0]; $limit_1=substr_count($html,$f_forma_name.'.'.$f_n ame.'.value'); $limit_2=substr_count($html_str,'Логин'); $limit_3=substr_count($html_str,'Имя персонажа'); if($data_form_auth!='' and $znak!='&'){$znak='&';}; if($f_type=='password'){$data_form_auth.=$znak.''. $f_name.'='.$game_pass_u;} elseif(($limit_2 > 0 || $limit_3 > 0) and $f_type=='text'){$data_form_auth.=$znak.$f_name.'= '.$game_login_u;} elseif($limit_1==2){$data_form_auth.=$znak.$f_name .'='.$f_java_value;} elseif($f_type=='image' and $f_name=="lbut"){$data_form_auth.=$znak.'lbut.x='.$lbutx.'&lbut.y='.$lbuty;} elseif($f_type=='hidden'){$data_form_auth.=$znak.$ f_name.'='.$f_value;}; ++$key; };

в итоге получалось по типу такого: login=rcc0023&pass=hohoho&preseted=1

Как можно сделать оптимальней?

rcc0023
17.04.2009, 06:00
более раскрыто...

$lbutx=rand(1,57);
$lbuty=rand(1,17);

$game_login_u=rawurlencode($game_login);
$game_pass_u=rawurlencode($game_pass);

$html=file_get_contents(index.php');

$html=str_replace('"','',$html);
$html=str_replace("'",'',$html);
$html=str_replace('>',' >',$html);
$html_2=str_replace(' ','',$html);

$text_01='<input';

$text_1=explode($text_01,$html);
$text_2=explode('<form',$html);
$text_3=explode('>',$text_2[1]);
$text_12=explode('name=',$text_3[0]);
$text_13=explode(' ',$text_12[1]);
$text_14=explode('action=',$text_3[0]);
$text_15=explode(' ',$text_14[1]);

$f_forma_name=$text_13[0];
$f_forma_action=$text_15[0];

$no_error_1=substr_count($html,$text_01);

while($no_error_1 >= $key){

$html_str2=explode('>',$text_1[$key]);

$html_str=$html_str2[0];

$text_4=explode('name=',$html_str);
$text_5=explode(' ',$text_4[1]);
$text_6=explode('type=',$html_str);
$text_7=explode(' ',$text_6[1]);
$text_8=explode('value=',$html_str);
$text_9=explode(' ',$text_8[1]);
$text_10=explode($f_forma_name.'.'.$text_5[0].'.value=',$html_2);
$text_11=explode(';',$text_10[2]);

$f_name=$text_5[0];
$f_type=$text_7[0];
$f_value=$text_9[0];
$f_java_value=$text_11[0];

$limit_1=substr_count($html,$f_forma_name.'.'.$f_n ame.'.value');
$limit_2=substr_count($html_str,'Логин');
$limit_3=substr_count($html_str,'Имя персонажа');

if($data_form_auth!='' and $znak!='&'){$znak='&';};

if($f_type=='password'){$data_form_auth.=$znak.''. $f_name.'='.$game_pass_u;}
elseif(($limit_2 > 0 || $limit_3 > 0) and $f_type=='text'){$data_form_auth.=$znak.$f_name.'= '.$game_login_u;}
elseif($limit_1==2){$data_form_auth.=$znak.$f_name .'='.$f_java_value;}
elseif($f_type=='image' and $f_name=="lbut"){$data_form_auth.=$znak.'lbut.x='.$lbutx.'&lbut.y='.$lbuty;}
elseif($f_type=='hidden'){$data_form_auth.=$znak.$ f_name.'='.$f_value;};

++$key;

};

Gifts
17.04.2009, 09:56
Зачем каждый раз парсить форму, особенно, когда он не меняется? Для логина на HWM надо передавать :

'LOGIN_redirect=1&login='.$login.'&lreseted=1&pass='.$passw.'&preseted=1&lbut.x=61&lbut.y=13'

Вот для записи на работу - да, надо будет парсить страницу

Gar|k
17.04.2009, 11:27
rcc0023 учи регулярки... уже в 4 темах отвечал подобных
в одной даже очень подробно описал что да как...