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.

Member Avatar for P0lT10n

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);
	
?>

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?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.