Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP CURL: Login to HTACCESS directory; POST username/password to FORM

Status
Not open for further replies.

iteach2

Technical User
Sep 16, 2001
120
US
Hi,

I have a curl script that I am developing, it needs to post username and password to a windows authentification, then on the next page is a form looking for username and password. How do I post to the windows authentification(.htaccess) then post to the login form a user and password, then post to a form that updates a textfield and submits.

This is what I was thinking
Code:
////SIGN INTO HTACCESS

$headers = array(	"Authorization: Basic " . base64_encode(sprintf('%s:%s', 'username', 'pass'))	);
		curl_setopt($ch, CURLOPT_URL, $loginurl);
		curl_setopt($ch, CURLOPT_USERPWD, 'user:pass');
		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
		curl_setopt($ch, CURLOPT_HEADER, 0);
		curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
		curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
		curl_setopt($ch, CURLOPT_TIMEOUT, 500);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_PORT, 443);
		// cookies
		curl_setopt($ch, CURLOPT_COOKIESESSION, true);
		curl_setopt($ch, CURLOPT_COOKIEJAR, './cookiejar'.time().'.txt');
		// post fields
		curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $arraydata);
		// SSL
		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
		// PROXY
		curl_setopt ($ch, CURLOPT_HTTPPROXYTUNNEL, TRUE);
		curl_setopt ($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
		curl_setopt ($ch, CURLOPT_PROXY,"[URL unfurl="true"]http://proxy.");[/URL]
		// errors
		curl_setopt($ch, CURLOPT_VERBOSE, 1);
		curl_setopt($ch, CURLOPT_STDERR, $errfile);



//////////LOGIN TO SECOND FORM

$headers = array(	"Authorization: Basic " . base64_encode(sprintf('%s:%s', 'username', 'pass'))	);
		curl_setopt($ch, CURLOPT_URL, $loginurl);
		curl_setopt($ch, CURLOPT_USERPWD, 'user:pass');
		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
		curl_setopt($ch, CURLOPT_HEADER, 0);
		curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
		curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
		curl_setopt($ch, CURLOPT_TIMEOUT, 500);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_PORT, 443);
		// cookies
		curl_setopt($ch, CURLOPT_COOKIESESSION, true);
		curl_setopt($ch, CURLOPT_COOKIEJAR, './cookiejar'.time().'.txt');
		// post fields
		curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $arraydata);
		// SSL
		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
		// PROXY
		curl_setopt ($ch, CURLOPT_HTTPPROXYTUNNEL, TRUE);
		curl_setopt ($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
		curl_setopt ($ch, CURLOPT_PROXY,"[URL unfurl="true"]http://proxy.");[/URL]
		// errors
		curl_setopt($ch, CURLOPT_VERBOSE, 1);
		curl_setopt($ch, CURLOPT_STDERR, $errfile);


///THIRD SUBMIT FORM

$headers = array(	"Authorization: Basic " . base64_encode(sprintf('%s:%s', 'username', 'pass'))	);
		curl_setopt($ch, CURLOPT_URL, $loginurl);
		curl_setopt($ch, CURLOPT_USERPWD, 'user:pass');
		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
		curl_setopt($ch, CURLOPT_HEADER, 0);
		curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
		curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
		curl_setopt($ch, CURLOPT_TIMEOUT, 500);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_PORT, 443);
		// cookies
		curl_setopt($ch, CURLOPT_COOKIESESSION, true);
		curl_setopt($ch, CURLOPT_COOKIEJAR, './cookiejar'.time().'.txt');
		// post fields
		curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $arraydata);
		// SSL
		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
		// PROXY
		curl_setopt ($ch, CURLOPT_HTTPPROXYTUNNEL, TRUE);
		curl_setopt ($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
		curl_setopt ($ch, CURLOPT_PROXY,"[URL unfurl="true"]http://proxy.");[/URL]
		// errors
		curl_setopt($ch, CURLOPT_VERBOSE, 1);
		curl_setopt($ch, CURLOPT_STDERR, $errfile);


DO i just connect 2 times and post or can one curl connect handle all three request
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top