Transform code to Eval()

Asked

Viewed 225 times

0

I wanted to transform this code to Eval(), because it ta reading only the files like data.php html and php scripts not.

// arquivo cujo conteúdo será enviado ao cliente
$dataFileName = 'data.php';

while ( true )
{
    $requestedTimestamp = isset ( $_GET [ 'timestamp' ] ) ? (int)$_GET [ 'timestamp' ] : null;
    // o PHP faz cache de operações "stat" do filesystem. Por isso, devemos limpar esse cache
    clearstatcache();
    $modifiedAt = filemtime( $dataFileName );

    if ( $requestedTimestamp == null || $modifiedAt > $requestedTimestamp )
    {
        $data = file_get_contents( $dataFileName );

        $arrData = array(
            'content' => $data,
            'timestamp' => $modifiedAt
        );

        $json = json_encode( $arrData );
        echo $json;
        break;
    }
    else
    {
        sleep( 2 );
        continue;
    }
}
  • 2

    Can you explain better what you mean by transformar esse código para eval()?

  • 1

    http://rberaldo.com.br/server-push-long-polling-php-ios/ Watch the last comment of this post you will understand me better

  • The opening tag of this as <? Or <?php

  • 1

    The opening tag is <?php

  • @Lucasc. S, from this . php you want to make a request to data.php is that your question? Try to make it clearer, for you it may seem obvious but for others it is not.

2 answers

2

I think this might help:

ob_start(); // Ativa o buffer de saída
include($dataFileName); // Inclui o arquivo dentro do buffer
$data = ob_get_contents(); // Copia o buffer para a variável $data
ob_end_clean(); // descarta o conteúdo do buffer sem fazer nenhuma alteração na página

You basically run include content and send it to a variable without it interfering with the current script.

  • 1

    Hi Abriel I already revoked the problem, vlw by help ai ;D

1

If you want data.php be processed by the server pass it as a url, to file_get_contens().

$data = file_get_contents('http://localhost/projeto/template.php');

I made an example trying to simulate your error, create two files or processa.php and the template.php

php template.

<h1>template</h1>
<?php
     $i=0;
    while($i < 11){
        echo $i .'<br>';
        $i++;
    }
?>

parses.php

When executed this way the output was html and php code printed on the screen, ie not displayed the values of $i.

echo file_get_contents('template.php');

When placed as a url it printed the values of $i

echo file_get_contents('http://localhost/projeto/template.php');
  • 1

    Thank you very much!

  • 1

    To tell you the truth I’d already done the same thing only I didn’t get caught I don’t know why :/

  • 1

    Mano is now picking up but does not update the data being pulled from the data group

  • 1

    Create a file with a select for you to see and insert something in the table it does not update only appears when F5

Browser other questions tagged

You are not signed in. Login or sign up in order to post.