Showing results for 
Search instead for 
Did you mean: 

Anyone any good with PHP?

Posts: 268
Registered: ‎22-05-2011

Anyone any good with PHP?

Basically, I'm using PHP to scrape usage stats from the portal, but authentication is proving somewhat problematic.
I made a little HTML page just so I could see the bare minimum needed to login, the following successfully logs in:
<form action="" method="post">
<input type="text" name="username"></input>
<input type="password" name="password"></input>
<input type="text" name="authentication_realm"></input>
<input type="submit"></input>

However doing (what I think is) the same in PHP yields an invalid password message every time.
Here is the PHP Code:
$url = '';
//header('Content-Type: text/plain; charset=utf-8');  // optional
error_reporting(E_ALL | E_STRICT);
$context = stream_context_create(array(
    'http' => array(
        'method' => 'POST',
        'header' => implode("\r\n", array(
                'Content-type: application/x-www-form-urlencoded',

        'content' => http_build_query(array(
                'username'  =>      'houlton23',
'authentication_realm'    =>      '',
                'password'    =>      '<--password-->',
$page = file_get_contents($url, false, $context);
echo $page;

Hope someone can spot where I'm going wrong,
Alex Smiley
Posts: 9,926
Thanks: 1,265
Fixes: 71
Registered: ‎06-04-2007

Re: Anyone any good with PHP?

Two lines of thought.
1) I think a Content-Length header is needed if the request is passed as HTTP/1.0; not sure whether that applies here or not.
2) Just wondering if the problem is that the login page is separate from VMBU (and other Member Centre pages) so a session token has to be passed from page to page to authenticate the user. A normal browser will handle this routinely but this 'pretend' browser would need to emulate the process.