[GIS] How to login in GeoServer from a PHP application

geoserverPHPrest

I'm looking for advice how to login on GeoServer from PHP. I found much tutorial how to work with GeoServer through REST API and cURL: create workspaces, stores, etc. But still can't find how to login on GeoServer and still login to whole session. Is it possible?

In forums I found something but it does not work.

Any advice?

UPDATE

I change Acegi security to Spring Security and now code looks:

function loginGeoserver($username, $password) {

$geoserverURL = "http://localhost:8080/geoserver/j_acegi_security_check";

$post = http_build_query(array(
        "username" => $username,
        "password" => $password,
));

$context = stream_context_create(array("http"=>array(
    "method" => "POST",
    "header" => "Content-Type: application/x-www-form-urlencoded\r\n" .
            "Content-Length: ". strlen($post) . "\r\n",
    "content" => $post,
)));

$page = file_get_contents($geoserverURL, false, $context);


for($i = 0; $i < sizeof($http_response_header); $i++){

    $headerLine = $http_response_header[$i];

    $pos = strpos($headerLine, 'Set-Cookie');

    if ($pos === 0) {
            $str = explode("=",$headerLine);
            $value = explode(";",$str[1]);
            $cookieValue = $value[0];
            break;
    }

}

$cookieName = "JSESSIONID";
$cookieDomain = "http://localhost:8080";
$cookiePath = "/geoserver";
$cookieExpiration = 0;

setcookie($cookieName,$cookieValue,$cookieExpiration,$cookiePath);
echo $page;
return $cookieValue;
}

Now its return GeoServer index page but nothing more I still can't log in. How can I make Acegi authorization?

Best Answer

I think i found answer. I use php for create session. So i get session id, but its just php session NOT Geoserver becouse its Java applicaton. So from php i can just get session id.
If im wrong give me better answer.