leonapster
21-03-2008, 20:17
Ciao, devo eseguire il login su un forum phpbb, e quindi accedere alle pagine con accesso ristretto.
Sono riuscito a trovare la stessa cosa ma in php:
function login($username, $password)
{
global $_SERVER;
// Generate post string
$post_fields = $this->array_to_http(array(
'username' => $username,
'password' => $password,
'autologin' => 1,
'redirect' => 'index.php',
'login' => 'Log In',
));
// Init curl
$this->curl = curl_init();
// Set options
curl_setopt ( $this->curl, CURLOPT_URL, $this->phpbb_url . 'ucp.php?mode=login' );
curl_setopt ( $this->curl, CURLOPT_POST, true );
curl_setopt ( $this->curl, CURLOPT_POSTFIELDS, $post_fields );
curl_setopt ( $this->curl, CURLOPT_RETURNTRANSFER, true );
curl_setopt ( $this->curl, CURLOPT_HEADER, false );
curl_setopt ( $this->curl, CURLOPT_COOKIE, $this->cookie_name );
curl_setopt ( $this->curl, CURLOPT_COOKIEJAR, $this->cookie_name );
curl_setopt ( $this->curl, CURLOPT_COOKIEFILE, $this->cookie_name );
curl_setopt ( $this->curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT'] );
// Execute request
$result = curl_exec ( $this->curl );
// Error handling
if ( curl_errno ( $this->curl ) )
{
$this->error = array(
curl_errno($this->curl),
curl_error($this->curl),
);
curl_close ( $this->curl );
return false;
}
// Close connection
curl_close ( $this->curl );
// Return result
return true;
}
/*
@ Function : read() - Read a pages contents
@ About : Returns the contents of a url
@ Type : Public
*/
function read($page_url)
{
global $_SERVER;
// Init curl
$this->curl = curl_init();
// Set options
curl_setopt ( $this->curl, CURLOPT_URL, $this->phpbb_url . $page_url );
curl_setopt ( $this->curl, CURLOPT_POST, false );
curl_setopt ( $this->curl, CURLOPT_RETURNTRANSFER, true );
curl_setopt ( $this->curl, CURLOPT_HEADER, false );
curl_setopt ( $this->curl, CURLOPT_COOKIE, $this->cookie_name );
curl_setopt ( $this->curl, CURLOPT_COOKIEJAR, $this->cookie_name );
curl_setopt ( $this->curl, CURLOPT_COOKIEFILE, $this->cookie_name );
curl_setopt ( $this->curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT'] );
// Execute request
$result = curl_exec ( $this->curl );
// Error handling
if ( curl_errno ( $this->curl ) )
{
$this->error = array(
curl_errno($this->curl),
curl_error($this->curl),
);
curl_close ( $this->curl );
return false;
}
// Close connection
curl_close ( $this->curl );
// Return result
return $result;
}
Mi servirebbe una traduzione php->C#.
L'importante è che dopo che ho fatto il login possa accedere alle pagine ristrette.
Grazie
Sono riuscito a trovare la stessa cosa ma in php:
function login($username, $password)
{
global $_SERVER;
// Generate post string
$post_fields = $this->array_to_http(array(
'username' => $username,
'password' => $password,
'autologin' => 1,
'redirect' => 'index.php',
'login' => 'Log In',
));
// Init curl
$this->curl = curl_init();
// Set options
curl_setopt ( $this->curl, CURLOPT_URL, $this->phpbb_url . 'ucp.php?mode=login' );
curl_setopt ( $this->curl, CURLOPT_POST, true );
curl_setopt ( $this->curl, CURLOPT_POSTFIELDS, $post_fields );
curl_setopt ( $this->curl, CURLOPT_RETURNTRANSFER, true );
curl_setopt ( $this->curl, CURLOPT_HEADER, false );
curl_setopt ( $this->curl, CURLOPT_COOKIE, $this->cookie_name );
curl_setopt ( $this->curl, CURLOPT_COOKIEJAR, $this->cookie_name );
curl_setopt ( $this->curl, CURLOPT_COOKIEFILE, $this->cookie_name );
curl_setopt ( $this->curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT'] );
// Execute request
$result = curl_exec ( $this->curl );
// Error handling
if ( curl_errno ( $this->curl ) )
{
$this->error = array(
curl_errno($this->curl),
curl_error($this->curl),
);
curl_close ( $this->curl );
return false;
}
// Close connection
curl_close ( $this->curl );
// Return result
return true;
}
/*
@ Function : read() - Read a pages contents
@ About : Returns the contents of a url
@ Type : Public
*/
function read($page_url)
{
global $_SERVER;
// Init curl
$this->curl = curl_init();
// Set options
curl_setopt ( $this->curl, CURLOPT_URL, $this->phpbb_url . $page_url );
curl_setopt ( $this->curl, CURLOPT_POST, false );
curl_setopt ( $this->curl, CURLOPT_RETURNTRANSFER, true );
curl_setopt ( $this->curl, CURLOPT_HEADER, false );
curl_setopt ( $this->curl, CURLOPT_COOKIE, $this->cookie_name );
curl_setopt ( $this->curl, CURLOPT_COOKIEJAR, $this->cookie_name );
curl_setopt ( $this->curl, CURLOPT_COOKIEFILE, $this->cookie_name );
curl_setopt ( $this->curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT'] );
// Execute request
$result = curl_exec ( $this->curl );
// Error handling
if ( curl_errno ( $this->curl ) )
{
$this->error = array(
curl_errno($this->curl),
curl_error($this->curl),
);
curl_close ( $this->curl );
return false;
}
// Close connection
curl_close ( $this->curl );
// Return result
return $result;
}
Mi servirebbe una traduzione php->C#.
L'importante è che dopo che ho fatto il login possa accedere alle pagine ristrette.
Grazie