Hi all,

I have a requirement to implement sessions on 'part' of a site. As the session is not required for the majority of pages, I am only calling Zend_Session::start() in the init() method of the controller which controls all the pages which require the session.

The problem is that my client wants the site to be usable with cookies disabled. I appreciate all the security concerns, this is another issue! So, I have to use session ID's passed in the URL. This is what I have done:

A section in my config file:

[session]
use_cookies = off
use_only_cookies = off
strict = on
use_trans_sid = 1

Then as part of the bootstrap process:

// Setup session options
if ($config->session) {
        Zend_Session::setOptions($config->session->toArray());
}

So we should now have the Zend_Session configured correctly. Then I have a controller called book with the following functions:

public function init() {
   // Start the session
   Zend_Session::start();
}

public function indexAction() {
   // Just let the view render for now
}

Please note that I am using the ViewRenderer helper.  In the view:

<p>in book/index with session <?=SID?></p>
<a href='/book'/'>link</a>

The URL I use on my local machine for the project is http:// wetb.nidd.local/. So, if i try http://wetb.nidd.local/book/, I see something like:

in book/index with session PHPSESSID=e52d7461d4d021298ccb2e77316d3cba
link

But here is the problem: each time I refresh the page or click the 'link', I get a different session ID. In addition, the PHPSESSID is not getting appended to the link I put in my view.

I have also tried setting the session parameter directly in my php.ini file. The following straight php script:

<?php
session_start();
echo "<a href='sesstest.php'>link</a>";
echo SID;
?>

Gives the results I would expect, with the PHPSESSID appended to my link and same session id displayed on each click of the link or page refresh.

I would much appreciate any hints or tips that could be provided to get URL based session working in my project.

Many thanks, Greg Frith.

Reply via email to