Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
PHP session counter being updated twice but only called once?
  • In previous applications I used a PHP $_SESSION and it worked with no problems. I introduced the following code to a Fuel application and the counter is being updated by 2 instead of 1. If I increment by Zero then the counter is not updated. Any suggestions to fix the problem so the counter is only updated by one? // index.php
    <?php
     session_start();
    if(isset($_SESSION['counter']))
    &#123;
     $_SESSION['counter'] = 1 + $_SESSION['counter'];    // adds 2
     // $_SESSION['counter'] = 1 + (int) $_SESSION['counter'];  // adds 2
     // $_SESSION['counter'] = 0.1 + $_SESSION['counter']; // adds 0.2
     // $_SESSION['counter'] = 0 + $_SESSION['counter'];  // does not add anything 
    }
    else
    &#123;
     $_SESSION['counter'] = 0; // start  counter
    }
    
    // toggle previously used in a class, model or view
    // usually either 0 or 1 - true or false
    if( $_SESSION['counter'] % 2) 
    &#123;
       // do this 
    }
    else
    &#123;
      // do that
    }
    

    Update:
    I just cleared the session and the counter sequence is:
    0
    1
    3
    5
    7 Updated again:
    Counter works fine using iExplorer, FireFox, Opera and Safari. Only adds two using Chrome.
  • Fuel doesn't use PHP sessions, or $_SESSION. Use Fuels Session class instead, it's much more secure. As you your issue, check your webserver and fuel logs. I'm reasonably sure you're missing an image or a favicon or so which is requested by chrome, and is rewritten to your Fuel app by your webserver...
  • Harro Verton wrote on Tuesday 6th of September 2011:
    Fuel doesn't use PHP sessions, or $_SESSION. Use Fuels Session class instead, it's much more secure. As you your issue, check your webserver and fuel logs. I'm reasonably sure you're missing an image or a favicon or so which is requested by chrome, and is rewritten to your Fuel app by your webserver...

    Many thanks for the prompt reply. I checked the fuel logs, PHP logs and Apache logs but was unable to find a missing image or any other problems. I eventually tracked it down to a missing favicon.ico. This has caught me out before using CI. I thought that I had learnt my lesson :(

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion