Jump to content

PHP auto form filling


midnite

Recommended Posts

i would like to use PHP scripts to login to my account and fill a form. But i still cannot login yet :mellow:i have been using HTTP functions like http_post_data()http://hk2.php.net/manual/en/function.http-post-data.phpi have found a tutorial websitehttp://www.oooff.com/php-scripts/basic-cur...ll-tutorial.phpwhich uses curl_exec() functions.which is better? (But if any of them works, it will be fine :) )i have tried http_post_data(), but i cant see there exist any cookies information in the response. But i see lots of cookies when using Firefox Tamper Data or Firebug. i guess it is the reason why i failed to login.In addition, the system uses HTTPS, does it matter?Thanks for your kindly help or is there any existing cool tutorials on the web? :)

Link to comment
Share on other sites

You can access cookies with the $_COOKIE superglobal array. You won't get cookies with a POST request, at least not to my knowledge...What does your code look like?As for cool tutorials, there is http://www.evolt.org/PHP-Login-System-with-Admin-Features

Link to comment
Share on other sites

You can access cookies with the $_COOKIE superglobal array. You won't get cookies with a POST request, at least not to my knowledge...What does your code look like?As for cool tutorials, there is http://www.evolt.org/PHP-Login-System-with-Admin-Features
Hi Synook, Thanks for your reply.i think i did not explain my situation clearly. i have an Apache PHP server. And i would like to write a PHP script to login to my school's account. Not building my own login system or forms.And my code is: (i have simplified for some string manipulate functions)
$SRC['base'] = 'https://www.myschoolweb.edu.hk/';$SRC['login'] = 'WWWLogin';$SRC['target'] = 'WWWLogin';// login form$websrc = http_get ($SRC['base'].$SRC['login'], array(), $info);$HEADER = http_parse_headers ($websrc);// make POST$SESS = 'something';$IP = 'somethingelse';$POST_DATA = 'p_username=myusername&p_password=mypassword&p_sess_id='.$SESS.'&p_ip='.$IP;foreach ($HEADER['Set-Cookie'] as $key => $value) {  $tmp_arr = explode ('=', $value, 2);  $COOKIE_arr[$tmp_arr[0]] = $tmp_arr[1];  $COOKIE_raw .= $value.';';}// submit login$FORM_OPTS = array (  'Host'			=> 'www.myschoolweb.edu.hk',  'User-Agent'	  => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-TW; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14',  'Accept'		  => 'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5',  'Accept-Language' => 'en-gb',  'Accept-Encoding' => 'gzip,deflate',  'Accept-Charset'  => 'UTF-8,*',  'Keep-Alive'	  => '300',  'Connection'	  => 'keep-alive',  'Referer'		 => 'https://www.myschoolweb.edu.hk/WWWLogin',  'Cookie'		  => $COOKIE_raw,  'Content-Type'	=> 'application/x-www-form-urlencoded',  'Content-Length'  => strlen ($POST_DATA),  'POSTDATA'		=> $POST_DATA);echo http_request (HttpRequest::METH_POST, $SRC['base'].$SRC['target'], '', $POST_OPTS, $info);//echo http_post_data ($SRC['base'].$SRC['target'], $POST_DATA, $FORM_OPTS, $info);print_r ($info);

the main problem is i cant find the returned session id cookie, which i saw in "Tamper Data" and "Firebug" :)

Link to comment
Share on other sites

The cookies will be in the headers. What is in the $HEADER array if you use print_r on it?
Thanks, justsomeguy!i have looked into the header. It is funny (or i dont understand why) that the print_r ($HEADER) is different from the first part of echo $websrc. (i post them later)And also, my school's login uses HTTPS. i wonder if these HTTP functions support HTTPS?Thanks again for your help!cheer.
Link to comment
Share on other sites

Thanks, justsomeguy!i have looked into the header. It is funny (or i dont understand why) that the print_r ($HEADER) is different from the first part of echo $websrc. (i post them later)And also, my school's login uses HTTPS. i wonder if these HTTP functions support HTTPS?Thanks again for your help!cheer.
Nope, i said wrongly. The are the same, of course, as $HEADER is extracted from $websrc. But what is different is $HEADER and $info.i am now fixing my code =)
Link to comment
Share on other sites

i am not familiar with HTTPS. i am not sure if pecl-http support SSL. But i found something interesting. When i use http_get ('https://'.$somethingelse), it is alright. Yet an error message saying it doesn't support SSL with i use http_get ('ssl://'.$somethingelse).And thanks all the guys who have helped me =)i am now using another approach - fsockopen(). And it works!! i have successfully logged in and now proceeding form by form =)http://us2.php.net/manual/en/function.fsockopen.php

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...