0

I have issues sometimes with CakePhp.

1 - When they users logged in, I save the username in Session, and also do some Cache logic to avoid some useless queries:

    $cacheTime = '24h';
    $cacheKey = md5(self::SITE_NAME . ' - ' . $login);

    $cachedLogin = Cache::read($cacheKey, $cacheTime);
    if ($cachedLogin) {

        $this->log('Already logged in : ' . $cachedLogin, 'curl');

        $this->Session->write('user_logged', 1);
        $this->Session->write('username', $cachedLogin);

        $this->redirect(array('controller' => 'interactions', 'action' => 'pronostics', '?' => array('disclaimer_popup' => 1)));
    }

Then when they click on disconnect, sometimes, I don't have the username set in the Session:

if ($this->Session) {
    $cacheKey = md5(self::SITE_NAME . ' - ' . $this->Session->read('username'));
    $cacheTime = '24h';
    Cache::delete($cacheKey, $cacheTime);

    $this->log('Logout : ' . $this->Session->read('username'), 'curl');

    $this->Session->destroy();
}

When I check logs, sometimes I don't have username set (I get : Logout : instead of Logout : kamelmah for example )

2 - I have the same issue on my payments controller : I use Paypal in order to make users subscribing my services. For 95% of the transactions everything goes well, but for 5% of them , I lost datas between the beginning and the end of the process. Beginning is to choose username, email, password ; I set this in a Session. When the payment is done, I create the entry in db with informations stored in the session but I have issues with 5% of them because datas stored in session are lost and I dunno why.

Is theses kind of issues happens often for you also ? What did you do to fix it ?

Thanks.

Meer
  • 1,006
  • 10
  • 15
zeflex
  • 1,487
  • 1
  • 14
  • 29
  • Those 5% have cookies disabled. – EternalHour Oct 13 '14 at 02:58
  • Really ? In this case how do I check if they have cookies disabled in order to 'optimise' my registratin system ? – zeflex Oct 13 '14 at 03:02
  • If the user has cookies disabled, it is very difficult for them to have a normal browsing experience. It also makes it difficult for you as a developer. You could show them a notice and ask them to enable cookies. The way to handle it is to pass an identifier in the URL as a query string from page to page so you know who is logged in. Then when you need the information you normally have saved in your session, do a DB query for it. – EternalHour Oct 13 '14 at 03:15
  • OK I will add some tweaks in order to catch this kind of situations. Thanks. – zeflex Oct 13 '14 at 03:16
  • I believe this page will help you. http://notes.dustinczysz.com/post/89706351174/php-sessions-vs-cookies – EternalHour Oct 13 '14 at 03:17
  • Thanks. BTW, I don't want to use get params to follow the session_id through registration process. Will it be better to use user ip and uses cakephp Cache system ? – zeflex Oct 13 '14 at 03:23
  • As long as you're not storing the IP permanently it should be fine, personally I would use the session id. – EternalHour Oct 13 '14 at 03:30
  • Ok I will think to both solutions tomorrow taking my time. Thanks ! – zeflex Oct 13 '14 at 03:31

0 Answers0