0

I'm trying to access an https site by passing the username and password into the code, however, the website is denying me access due to 'browser caching issue', can someone help please? here is the code:

$client = new Zend_Http_Client();

$client->setUri('https://www.example.com');
$client->setParameterPost(array(
    'username' => 'username',
    'password' => 'password'
));


$client->request(Zend_Http_Client::POST);
$response = $client->request();

echo $response->getBody();
falsetru
  • 357,413
  • 63
  • 732
  • 636
user2045298
  • 11
  • 1
  • 4

2 Answers2

1

Why are you calling $client->request() twice? You probably should call it one.

In addition, the reason could be specific to the site (you did not specify which site it is). For example, many sites implement some kind of CSRF protection token or other security measure which will require you to first GET the log-in page, grab some hidden field value from it and re-send it in the log-in POST request. This is quite typical and I suggest you use Chrome developer tools, Firebug or a similar tool to manually submit the log-in form from your browser, and check which other form values are sent on log-in beyond just the username and the password.

shevron
  • 3,463
  • 2
  • 23
  • 35
  • This is the site https://www.lib.uts.edu.au/auth/login?service=https%3A%2F%2Fwww.lib.uts.edu.au%2Fgoto%3Fqurl%3Dhttp%253a%252f%252fclients1.ibisworld.com.au%252freports%252fau%252findustry%252fkeystatistics.aspx%253fentid%253d116%26_casCheck%3Dtrue# I tried using firebug but I couldn't pin point which other fields I need to pass, your help is much appreciated. – user2045298 Aug 07 '13 at 07:10
  • The credentials I'm using are the 'student Id' and 'password' – user2045298 Aug 07 '13 at 07:12
0

I sorted out the problem, the code is supposed to work but the site has a security hash that prevents me from accessing it that way.

user2045298
  • 11
  • 1
  • 4
  • You can most likely still work around the problem by extracting that hash using DOM (or if you have to a regex), and sending it in the next request. – shevron Aug 30 '13 at 09:48