Welcome Guest, Not a member yet? Register   Sign In
Lost session
#1

Don't know if am the only one who witnessed this, the session is lost when a redirection occurs.
Reply
#2

Have the session active int the page where you are redirected?
Does any Exception appear?
Reply
#3

You're not likely to fix the problem without showing us your session config, and how you are using session.
Reply
#4

well the session is initiated in a core controller

function __construct(...$params)
{
parent::__construct(...$params);

Asset::_init();

// Ensure session is running
session()->start();
}




and the session settings



public $sessionDriver = 'CodeIgniter\Session\Handlers\FileHandler';
public $sessionCookieName = 'icvent_session';
public $sessionExpiration = 7200;
public $sessionSavePath = '../../Tarena/writable/temp';
public $sessionMatchIP = false;
//public $sessionTimeToUpdate = 0;
public $sessionTimeToUpdate = 300;
public $sessionRegenerateDestroy = false;
Reply
#5

note, when i downgrade to php 5.6, it works well
Reply
#6

This is how I start the sessions in a BaseController

PHP Code:
<?php namespace App\Controllers;

/**
 * ---------------------------------------------------------------------------
 * Editor   : PhpStorm 2018.1.1
 * Date     : 01/09/2018
 * Time     : 10:22 AM
 * Authors  : Raymond L King Sr.
 * ---------------------------------------------------------------------------
 * 
 * Class        BaseController
 * 
 * @project     ci4
 * @author      Raymond L King Sr.
 * @link        http://www.procoversfx.com
 * @copyright   Copyright (c) 2009 - 2018 Pro Covers FX, LLC.
 * @license     http://www.procoversfx.com/license
 * ---------------------------------------------------------------------------
 */

use CodeIgniter\Controller;

/**
 * Class BaseController
 *
 * @package App\Controllers
 */
class BaseController extends Controller
{
    
/**
     * Class variables - public, private, protected and static.
     * -----------------------------------------------------------------------
     */

    /**
     * @var  array
     */
    
protected $helpers = [];

    
/**
     * __construct ()
     * -----------------------------------------------------------------------
     *
     * Class    Constructor
     *
     * NOTE: Not needed if not setting values or extending a Class.
     *
     */
    
public function __construct(...$params)
    {
        
parent::__construct(...$params);

 
       // Ensure session is started and running
 
       if (session_status() == PHP_SESSION_NONE)
 
       {
 
           // session has not started so start it
 
           session()->start();
 
       }
    }

  // End of BaseController Class.

/**
 * ---------------------------------------------------------------------------
 * Filename: BaseController.php
 * Location: ./application/Controllers/BaseController.php
 * ---------------------------------------------------------------------------
 */ 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#7

Tried this, still same thing, once the page redirects, the session is get destroyed
Reply
#8

Your sessSavePath doe's not look right to me, I do it like below.

PHP Code:
// change this to below
public $sessionSavePath '../../Tarena/writable/temp';

// change to this
public $sessionSavePath WRITEPATH.'temp/'

See if that makes a difference.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#9

(04-21-2018, 03:59 AM)InsiteFX Wrote: Your sessSavePath doe's not look right to me, I do it like below.

PHP Code:
// change this to below
public $sessionSavePath '../../Tarena/writable/temp';

// change to this
public $sessionSavePath WRITEPATH.'temp/'

See if that makes a difference.


maybe am not asking the right question, after the session is set, below is what its expected to be when it redirects.

PHP Code:
array(2) { ["__ci_last_regenerate"]=> int(1524320738) ["ticket_order_1448937565"]=> array(14) { ["validation_rules"]=> array(3) { ["ticket_holder_first_name06"]=> string(8"required" ["ticket_holder_last_name06"]=> string(8"required" ["ticket_holder_email06"]=> string(20"required|valid_email" } ["validation_messages"]=> array(3) { ["ticket_holder_first_name06"]=> array(1) { ["required"]=> string(40"Ticket holder 1's first name is required" } ["ticket_holder_last_name06"]=> array(1) { ["required"]=> string(39"Ticket holder 1's last name is required" } ["ticket_holder_email06"]=> array(2) { ["required"]=> string(35"Ticket holder 1's email is required" ["valid_email"]=> string(37"Ticket holder 1's email must be valid" } } ["event_id"]=> string(1"7" ["tickets"]=> array(1) { [0]=> array(6) { ["ticket"]=> object(App\Icon\Entities\Tickets\Ticket)#164 (28) { ["ticket_id":protected]=> string(1) "6" ["ticket_event":protected]=> string(1) "7" ["ticket_title":protected]=> string(7) "Another" ["ticket_description":protected]=> string(0) "" ["event_venue_name":protected]=> NULL ["ticket_user":protected]=> string(1) "1" ["event_is_live":protected]=> NULL ["event_venue_name_full":protected]=> NULL ["ticket_quantity_available":protected]=> string(2) "20" ["ticket_max_per_person":protected]=> string(2) "30" ["ticket_start_sale_date":protected]=> string(19) "2018-02-28 17:00:00" ["ticket_end_sale_date":protected]=> NULL ["ticket_created_at":protected]=> string(19) "2018-03-09 15:54:08" ["ticket_updated_at":protected]=> string(19) "2018-04-19 21:13:50" ["ticket_deleted":protected]=> string(1) "0" ["ticket_is_hidden":protected]=> string(1) "0" ["ticket_price":protected]=> string(6) "400.00" ["ticket_is_paused":protected]=> string(1) "0" ["ticket_sort_order":protected]=> string(1) "2" ["ticket_organiser_fees_volume":protected]=> string(4) "0.00" ["ticket_quantity_sold":protected]=> string(1) "0" ["ticket_sales_volume":protected]=> string(4) "0.00" ["ticket_status":protected]=> NULL ["_options":protected]=> array(3) { ["datamap"]=> array(0) { } ["dates"]=> array(4) { [0]=> string(17) "ticket_created_at" [1]=> string(17) "ticket_updated_at" [2]=> string(22) "ticket_start_sale_date" [3]=> string(20) "ticket_end_sale_date" } ["casts"]=> array(0) { } } ["relatives":protected]=> array(0) { } ["ticket_edited_by"]=> NULL ["ticket_min_per_person"]=> string(1) "1" ["ticket_public_id"]=> NULL } ["qty"]=> int(1) ["price"]=> float(400) ["booking_fee"]=> float(0) ["organiser_booking_fee"]=> float(0) ["full_price"]=> float(400) } } ["total_ticket_quantity"]=> int(1) ["order_started"]=> int(1524320738) ["expires"]=> object(Carbon\Carbon)#150 (3) { ["date"]=> string(26) "2018-04-21 15:35:38.759239" ["timezone_type"]=> int(3) ["timezone"]=> string(12) "Africa/Lagos" } ["reserved_tickets_id"]=> int(13) ["order_total"]=> float(400) ["booking_fee"]=> float(0) ["organiser_booking_fee"]=> float(0) ["total_booking_fee"]=> float(0) ["order_requires_payment"]=> bool(true) ["event_owner"]=> string(1) "1" } } 


but after the redirect, here is what is left

PHP Code:
array(1) { ["__ci_last_regenerate"]=> int(1524320922) } 

note, the redirect is done with ajax.

below is the code from the setting of the session downward.


PHP Code:
/*
        * The 'ticket_order_{event_id}' session stores everything we need to complete the transaction.
        */
     
     session()->set('ticket_order_' $event_Id, [
     
     'validation_rules'        => $validation_rules,
     
     'validation_messages'     => $validation_messages,
     
     'event_id'                => $event->event_id,
     
     'tickets'                 => $tickets,
     
     'total_ticket_quantity'   => $total_ticket_quantity,
     
     'order_started'           => time(),
     
     'expires'                 => $order_expires_time,
     
     'order_total'             => $order_total,
     
     'order_requires_payment'  => (ceil($order_total) == 0) ? false true,
     
     'event_owner'              => $event->user->user_id,
     
     ]);
     
     

          
/*
        * If we're this far assume everything is OK and redirect them
        * to the the checkout page.
       */
     
  //var_dump($_SESSION);
     
   //die;
     
     if ($this->request->isAJAX()) 
     
     {
     
     return json_encode([
     
        'status'      => 'success',
     
        'redirectUrl' => route_to('showEventCheckout',$event_Id,$event->event_slug),
     
     ]);
     
     }else{
 
             /*
            * Maybe display something prettier than this?
            */
 
             exit('Please enable Javascript in your browser.');
     
     
Reply
#10

I think you are asking the right question. Something in the session config is not correct resulting in "lost" sessions.

I'm not truely up to speed with CI 4 but I think your $sessionDriver value looks wrong. Try this.

PHP Code:
public $sessionDriver 'files'

And as @InsiteFX suggests, make sure the file path is correct. Of particular importance is that only absolute paths are supported for $sessionSavePath.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB