I’m designing a survey module using CakePHP.
The purpose of this module is to be called from a foreign site by this code:
<script type="text/javascript"
src="http://global_survey.localhost/visitor_sessions/init/1234">
</script>
Obviously, localhost will be replaced with the production server when live.
I am creating the cookie with Cake’s CookieComponent.
When the remote site calls the init method, the cookie is not visible on the
client system
When I call the init component directly in the browser to test the cookie
functionality, I discover that I am not saving my cookie, even though I set
$this->Cookie->time=100;
The cookie is visible in my browser when I am calling the init method
directly.
The code is as follows:
class VisitorSessionsController extends AppController {
var $name = 'VisitorSessions';
var $helpers = array('Html', 'Form','Ajax','Javascript');
var $components = array( 'RequestHandler', 'Auth','Cookie');
function beforeFilter(){
parent::beforeFilter();
$this->Auth->allow(
array(
'init',
'refresh',
'respond',
'end'
)
);
$this->Cookie->name='visitor_session';
$this->Cookie->domain='global_survey_client.localhost';
$this->Cookie->time=100;
}
function init($site_id = null){
$this->layout='ajax';
Configure::write('debug',0);
// check for existing sessions with this ip address
$ip_addr = env('REMOTE_ADDR');
$this->set('ip_addr',$ip_addr);
$num_times=$this->Cookie->read('num_times');
$this->Cookie->write('test','test');
$this->Cookie->write('num_times',($num_times?$num_times:0)+1);
$num_times=$this->Cookie->read('num_times');
$test=$this->Cookie->read('test');
$this->set('test',$test);
$this->set('num_times',$num_times);
// if no current cookie
// create cookie
// create session
// set ip address
// set hit times
// else
// load current cookie
// update current session
// update last hit.
// create javascript with links to active session
}
function refresh($session_id=null){
// update session.last_hit
}
function respond($session_id=null){
}
}
In my init.ctp, I only have this simple code for now:
alert('test <?php __($test);?> (<?php __($num_times);?>)');
The stored value is not incrementing… Ultimately, I want to store my cookie
for the life of the browser, and create a new session when the user closes
the current browser instance, and then goes back to the client website at
some later date.
Can anybody tell me what I am doing wrong?
I’m trying to look on google and the cookbook for how to do this properly,
and I am having trouble finding anything.
Thank you all very much.
<http://www.connaxis.com/> <http://www.connaxis.com/>
<http://www.connaxis.com/> <http://www.connaxis.com/>
<http://www.connaxis.com/> <http://www.connaxis.com/> David Kenneth Coleman
Software Developer
…………………………………………………………………………………………………………………
United States: +
1 6468108783 Dept: Development
Argentina:
+ 54 11 52465987 E-mail: <mailto:[email protected]>
[email protected]
The Netherlands: + 31
208080017 Skype: david.k.coleman
¡ <http://www.connaxis.com/> <http://www.connaxis.com/>
<http://www.connaxis.com/> <http://www.connaxis.com/>
<http://www.connaxis.com/> <http://www.connaxis.com/> NEW! Please check out
our new <http://www.creative-outsourcing.com/> Portfolio Website:
<http://www.creative-outsourcing.com/> Connaxis Creative Outsourcing
Specialist <http://www.creative-outsourcing.com/>
www.creative-outsourcing.com
First page position Google.com:
<http://www.google.com/search?hl=en&q=creative+outsourcing&btnG=Google+Searc
h> Creative Outsourcing
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---
<<inline: image001.jpg>>
