Skip to content

Commit

Permalink
method to manually set the session cookie
Browse files Browse the repository at this point in the history
  • Loading branch information
dready92 committed Dec 1, 2010
1 parent 286073c commit c217c37
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
6 changes: 6 additions & 0 deletions doc/couch_client-database.md
Expand Up @@ -21,6 +21,12 @@ Example : as the previous one, but using cookie based authentification

$client = new couchClient("http://couchAdmin:secret@my.server.com:5984/","mydb", array("cookie_auth"=>TRUE) );

You can also set manually the session cookie.

Example : manually setting the session cookie :

$client = new couchClient("http://my.server.com:5984/","mydb");
$client->setSessionCookie("AuthSession=Y291Y2g6NENGNDgzNzY6Gk0NjM-UKxhpX_IyiH-C-9yXY44");



Expand Down
10 changes: 10 additions & 0 deletions lib/couch.php
Expand Up @@ -42,6 +42,7 @@ class couch {
* @var array allowed HTTP methods for REST dialog
*/
protected $HTTP_METHODS = array('GET','POST','PUT','DELETE','COPY');

/**
* @var resource HTTP server socket
* @see _connect()
Expand Down Expand Up @@ -93,6 +94,15 @@ public function options() {
return $this->options;
}

/**
* set the session cookie to send in the headers
* @param string $cookie the session cookie ( example : AuthSession=Y291Y2g6NENGNDgzNz )
*/
public function setSessionCookie ( $cookie ) {
$this->sessioncookie = $cookie;
return $this;
}


/**
* return a part of the data source name
Expand Down
2 changes: 1 addition & 1 deletion lib/couchClient.php
Expand Up @@ -123,7 +123,7 @@ public function __construct($dsn, $dbname, $options = array() ) {
if ( strpos($line,"Set-Cookie: ") === 0 ) {
$line = substr($line,12);
$line = explode("; ",$line,2);
$this->sessioncookie = reset($line);
$this->setSessionCookie(reset($line));
break;
}
}
Expand Down

0 comments on commit c217c37

Please sign in to comment.