CURL and PHP, auto login script.
Posted: Sat Jun 16, 2007 3:54 pm
feyd | Please use
Thanks!
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I have a login/pass to a website, basiclly looks here: http://www.exclusivepath.com/login.aspx ...
Generally what I do is login, and then backup the specific file in a excel sheet. I do this everyday, once a day.
What I wanted was a script that grabs that automatically. It should be easy enough cept for the login part....
I'm not sure how I can make it fill in those fields first, hit Login, and wait until thats complete to continue. Does anyone have any suggestions or scripts that may do this?
I have a example script I played around with. I got it to login PHPbb2 forums with some modifications, but not at http://www.exclusivepath.com/login.aspx ... Am I missing something here?
Here is the coding so far for the auto login:Code: Select all
<?php
echo login_curl();
function login_curl()
{
//Define form data array
$postfields = array();
$postfields["UserName"] = urlencode("xxxxx");
$postfields["Password"] = urlencode("xxxxx");
$postfields["Button1"] = urlencode("Login");
//Define option variables
$action ="http://www.exclusivepath.com/login.aspx";
$cookie = "cookie.txt";
$agent = "Mozilla/5.0";
$referer = "http://www.exclusivepath.com/login.aspx";
//Initialize a CURL session
$ch = curl_init($action);
//Set the CURL options
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_REFERER, $referer);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
//Capture output and close session
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
?>feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]