What problems will I have in using ob_start () and ob_end_flush ()?

2

My application is a site for a real estate agent and I'm having trouble with a resource developed with a shopping cart-like session to add more than one property to a single proposal. The problem that is happening is that when selected a property is created the session however, there are times that the property appears in the list of requests and has times that do not, and has times that only appears after a certain time (delay).

Can this problem be related to ob_start () and end_flush ()? Could anyone give me any hints of what might be going on?

My application looks like this:

<?php
    ob_start();
    session_start();
    require('includes/paginator.class.php');
    require('includes/cookie.class.php');  
    require('config/get.php');
    require('config/config.php');
    require_once ('includes/recaptchalib.php');
    require_once('classes/Conexao.php');
    require_once('classes/Carrinho.php');

    <conteúdo estatico head>

<conteúdo estatico header>

    <conteúdo dinamico com includes das páginas(contato/institucional/pedido/etc)>

    <conteúdo estático footer>
    end_flush();
    ?>
    
asked by anonymous 01.10.2015 / 15:56

2 answers

2

When you use ob_start(); and end_flush(); You are loading a content buffer. I do not recommend that you put class, connection, and config requests within these functions, so you can use session_start(); or setcookie() .

In your case, I think you could solve your problem by doing something like this:

<?php
session_start();
require('includes/paginator.class.php');
require('includes/cookie.class.php');  
require('config/get.php');
require('config/config.php');
require_once('includes/recaptchalib.php');
require_once('classes/Conexao.php');
require_once('classes/Carrinho.php');

if (session_id() == '') {
   echo "A sessão expirou!";
   die();
}

echo getTemplate('arquivo_externo');

  function getTemplate($file) {
      ob_start();
      include $file.'.php';
      $template = ob_get_contents(); 
      ob_end_clean();
      return $template;
      end_flush();
  }
    
01.10.2015 / 16:32
1

My problem was not exactly with ob_start (), but the server cache. I am hosting in kinghost with the active varnish cache server which totally bugged my application, for the simple fact that this server is storing the sessions and the cookies and not in the user machine, after deactivating the cache server everything returned to normal. p>

Thank you for the answers. Problem solved.

    
22.10.2015 / 19:21