954,597 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Creating a PHP Bot

I am trying to create a PHP bot for a project for my cs classs that will automatically log me in to a site and perform certain tasks once that is complete. I have been doing some research and I believe the best way to acomplish this would be wish cURL however I am new to PHP so I may be taking the wrong approach. Here is what I have so far:

<?php
	$curl = curl_init();
	curl_setopt ($curl, CURLOPT_URL, "http://www.mywebsite.com");
	curl_setopt ($curl, CURLOPT_POST, 1);
	curl_setopt ($curl, CURLOPT_POSTFIELDS, "usr=username&pswd=password");
	
	curl_exec($curl);
	echo curl_error($curl);
	curl_close($curl);
	
?>


When I run this script I just get a broken link error in my browser, can anyone offer any suggestions? Thanks for your help.

haye321
Newbie Poster
3 posts since Dec 2010
Reputation Points: 10
Solved Threads: 0
 

this is your code:

<?php
	$curl = curl_init();
	curl_setopt ($curl, CURLOPT_URL, "http://www.mywebsite.com");
	curl_setopt ($curl, CURLOPT_POST, 1);
	curl_setopt ($curl, CURLOPT_POSTFIELDS, "usr=username&pswd=password");
	
	curl_exec($curl);
	echo curl_error($curl);
	curl_close($curl);
	
?>

Try doing this:

<?php
	$curl = curl_init("http://www.mywebsite.com");
	curl_setopt ($curl, CURLOPT_POST, 1);
	curl_setopt ($curl, CURLOPT_POSTFIELDS, "usr=username&pswd=password");
	
	curl_exec($curl);
	echo curl_error($curl);
	curl_close($curl);
	
?>
P0lT10n
Posting Whiz in Training
235 posts since Apr 2010
Reputation Points: 13
Solved Threads: 30
 

I am still getting the broken link error, am I correct in assuming that the variables usr and pswd are supposed to be named the same as the forms that they correspond to on the pages I'm logging into?

haye321
Newbie Poster
3 posts since Dec 2010
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: