Ali
Ali

Reputation: 160

Submit a form automatically with PHP


I wanted to submit a form with php with special values but it's not working here is the code :

<?php
//create array of data to be posted
$post_data['username'] = 'something';
$post_data['password'] = 'something!';
//traverse array and prepare data for posting (key1=value1)
foreach ( $post_data as $key => $value) {
   $post_items[] = $key . '=' . $value;
}
//create the final string to be posted using implode()
$post_string = implode ('&', $post_items);
//create cURL connection
$curl_connection =curl_init('http://www.parsdata.com/');
//set options
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl_connection, CURLOPT_USERAGENT,
  "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);
//set data to be posted
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);
//perform our request
$result = curl_exec($curl_connection);
//show information regarding the request
print_r(curl_getinfo($curl_connection));
echo curl_errno($curl_connection) . '-' .
                curl_error($curl_connection);
//close the connection
curl_close($curl_connection);
?>

And this is what is returned :

Array ( [url] => http://www.parsdata.com/ [content_type] => text/html; charset=utf-8 [http_code] => 200 [header_size] => 328 [request_size] => 245 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 3.876425 [namelookup_time] => 0.031218 [connect_time] => 0.238176 [pretransfer_time] => 0.23823 [size_upload] => 56 [size_download] => 72015 [speed_download] => 18577 [speed_upload] => 14 [download_content_length] => 72015 [upload_content_length] => 56 [starttransfer_time] => 1.703701 [redirect_time] => 0 [certinfo] => Array ( ) [primary_ip] => 217.66.216.91 [primary_port] => 80 [local_ip] => 23.236.155.242 [local_port] => 43417 [redirect_url] => ) 0-

There wasn't any error but it doesn't work .
I really don't know what to do.
If you need a real user and pass I can give you !
Thank you in advance .

Upvotes: 0

Views: 97

Answers (3)

Rahul Shah
Rahul Shah

Reputation: 19

If you want to login to a website, all you need to do is to parse the Set-Cookie header in the response, and to pass the Cookie header to every request you'll do after dat.

Upvotes: 0

blue112
blue112

Reputation: 56462

Actually, it may works.

If you want to login to a website, all you need to do is to parse the Set-Cookie header in the response, and to pass the Cookie header to every request you'll do after that.

You can use a cookie jar to do that, more informations here : PHP Curl And Cookies

Upvotes: 1

Yash Sodha
Yash Sodha

Reputation: 703

You should use the correct URL for login. I visited the website and I found this URL for login - http://members.parsdata.com/default.aspx?dll=user&ctl=autosignin

Upvotes: 1

Related Questions