• Resolved 1inf3rn0

    (@1inf3rn0)


    Well,

    I am sure, there is much better way, to edit sessions, than I did.
    Anyway, I am not able to make it work.

    I need to setup session ID one time and left it there for 1year (expire time does not matter now – if 1day or 1year)

    In future, when the code will work, there will be session created only after user complete the form.

    The code bellow is typed into theme (DIVI) in functions.php
    and to the site I call this code via shortcodes [edit_sessions] and [locked_fce].

    That is working fine – what is not working fine, I can not see the session in Cookies in browser (I do not much care about this), but also the “coockie_lifetime” is not working for me. And it means, that when I closed browser …

    now its working well because I have $_SESSION['veryS3cr3tK3Ywh1chNeverW1LLbeF0UND'] = "S0M3_D4T4_1_N33D_L4T3R";
    without any condition

    function edit_session_id_when_user_sent_data() {
    	
    add_action('init', 'myStartSession', 1);
    add_action('wp_logout', 'myEndSession');
    add_action('wp_login', 'myEndSession');
    
    function myStartSession() {
    			if(!session_id()) {
    				session_start(['cookie_lifetime' => 876986798,]);
        						}
    						}
    
    function myEndSession() {
        session_destroy ();
    						}
    
    	$_SESSION['veryS3cr3tK3Ywh1chNeverW1LLbeF0UND'] = "S0M3_D4T4_1_N33D_L4T3R";
    	
    }
    
    add_shortcode('edit_session', 'edit_session_id_when_user_sent_data');
    
    function lock_until_login() {
    
    if(isset($_SESSION['veryS3cr3tK3Ywh1chNeverW1LLbeF0UND'])) {
    
    return "
    						
    <p><b>YOU ARE ALLOWED TO BE HERE</b></p>
    <p><i>Your session id is FINE </i></p>

    “;

    }
    }

    add_shortcode(‘locked_fce’, ‘lock_until_login’);`

    • This topic was modified 3 years, 8 months ago by 1inf3rn0.

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘session id not stored in cookie’ is closed to new replies.