开发者

Zend_Http_Client not storing cookies

I am using the following code to access a page protected by username/password login.

  //Fetch homepage
  $client = new Zend_Http_Client();
  $client->setCookieJar();
  $client->setUri('https://www.yourloungelearning.co.uk/crew_trainer/login.php');
  //$client->setParameterPost( 'username', $_SESSION['username'] );
  //$client->setParameterPost( 'password', $_SESSION['password'] );
  $client->setParameterPost( 'username', '#####' );
  $client->setParameterPost( 'password', '#####' );
  $response = $client->request('POST');

  // Now we're logged in, get private area! 
  $client->setUri('https://www.yourloungelearning.co.uk/crew_trainer/index.php');
  $response = $client->request('GET');

  echo $respons开发者_JAVA百科e->getBody();

The echo at the end always returns the login screen again (suggesting an unsuccessful login). This is copied almost exactly from the Zend docs. Can anyone see what I'm doing wrong?


A quick couple of tests on that page reveal that you do indeed need to include the submit button value (the actual value is irrelevant, it just has to be present) as part of the POST data for the login to be processed.

$client->setParameterPost('submit', 'Login');

You would have noticed this if you checked the response from the login attempt.


I had this problem yesterday, look at the API site.

->setCookieJar(true)

The parameter true constructs a new CookieJar, without this parameter it didn't work for me.


Not a solution, but: Instead of using just ->setCookieJar(), you should manually instantiate a Zend_Http_CookieJar and pass that. This way you can debug more easily if you've actually received a login cookie.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜