• Hi there,

    I have developed a plugin which create session while login (Not using wordpress default) but when I reload my page it got destroyed and showing this plugin session only not my created session but when I delete this plugin and destroy all session and then try to create session using login page then my plugin’s sessions are staying without any problem so I think this plugin is deleting my created session.

    So need a way to fix this issue.

    Here is the session data I am getting after reloading my page.

    array(4) { [“GOTMLS_SESSION_LAST”]=> float(1671801506.6523799896240234375) [“GOTMLS_SESSION_TIME”]=> float(1671801573.5380990505218505859375) [“GOTMLS_detected_attacks”]=> string(0) “” [“GOTMLS_login_attempts”]=> int(0) }

    NOTE: I created a function to start the session

    function register_session_new(){
    if( ! session_id() ) {
    session_start();
    }
    }
    add_action(‘init’, ‘register_session_new’);

    Still it got replaced by this plugin

    • This topic was modified 2 years, 2 months ago by masumbillah22. Reason: added session start function
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Eli

    (@scheeeli)

    Your code looks correct and sessions are meant to be globally accessible to any code that needs to access them. There is nothing in my code that clears or erases the session so it should not conflict with your plugin. Can you please send me the full code from your plugin so that I can test it on my site and figure out where the conflict is?

    You can email me directly if you don’t want to post it on this public forum:

    eli AT gotmls DOT net

    Thread Starter masumbillah22

    (@masumbillah22)

    I am really sorry for this delay.

    I have sent you and email with dropbox link so that you can download that plugin to check it.

    Thanks in Advanced

    Plugin Author Eli

    (@scheeeli)

    The first site I tried to test your Commission Calculator plugin on failed to create the tables on activation, I got the following error message in my log files:
    WordPress database error Invalid default value for 'created_at' for query CREATE TABLE wp_mbcc_install_type
    
    I am using PHP Version 7.4.8 and MySQL Client API library version 5.5.62 on that server.
    
    I was able to install and activate your plugin on one of my other servers though, and I get this error in your code when I run this plugin?on any of my test sites:
    Notice: Undefined index: ms_login in?.../wp-content/plugins/mb-commission-calculator/shortcodes/ms-commission-calculator.php?on line?26
    
    This is the code you have on that line:
    
    ? ? if($_SESSION['ms_login'] == false){
    
    You might want to rethink?your login conditions and take into account that there might not be a session at all the first time your code runs. For example this code change will fix that PHP Warning for you:
    
    ? ? if((isset($_SESSION['ms_login']) === false) || ($_SESSION['ms_login'] == false)){
    
    Also, your logout link is set to "?logout=true" which only works if you are using permalinks URLs and does not work on my test post ID 1732 which has a URL of /?p=1732 (your ?logout=true overwrites my post_id and thus it never triggers your shortcode on that page, therefore I cannot logout). I can only login if I hack the URL to include both parameters required for your plugin to successfully log me out:
    
    /?p=1732&logout=true
    
    Then I noticed that your code executes the?session_destroy() function on logout, which is not very friendly to any other plugins that might have stored any session variables for their own purposes. You will notice that my plugin never uses?session_destroy() or $_SESSION = ... specifically so that I don't step on anyone else's toes.
    
    Your login redirect also takes me away from the test post that?I put your shortcode on so after logging in I have to manually navigate back to?/?p=1732 to see your form.
    
    But, other than all those issues I had no problems with your session vars after logging?in, even with my plugin installed on that site too, so I don't see how my plugin has anything to do with whatever session issues you are having on your server. The only session vars accessed by my plugin are only within the array elements prefixed with GOTMLS, like $_SESSION["GOTMLS_... so my plugin cannot by overwriting your sessions.
    
    I think the fact that you are using @ini_set( 'display_errors', 0 ); is a bad sign. You shouldn't really be expecting to have so many errors that you would need to suppress them like that and you won't be able to troubleshoot the issue you are having in your plugin if you suppress the errors either. I think if your turn off error suppression and weed out all the bugs in your code that might be causing the errors you are hoping to suppress (mostly caused by assuming that variables exist and using them without testing them using if isset first) then you might be able to pin down whatever anomalies are producing this unwanted session loss on your server.
    
    If I had to guess I would say that you are probably getting cached results sometimes that are confusing the issue and making it hard for you to tell when you are getting real-time session results in your output.
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Session From Different Plugin Got Removed’ is closed to new replies.