Doubt fwrite writing in the file

Asked

Viewed 55 times

0

Talk guys, I have a problem writing to a file using fwrite, I can create the file normally but at the time of writing I get the following error:

Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in /home/i9pix942/public_html/i9/insert.php on line 36

I identified that the problem is inside: fwrite($Fp, "my code")

Good in there I have the following code that I need to insert into each created file. the code is this:

fwrite($fp,"error_reporting(0);

ini_set('display_errors', FALSE);

header('Access-Control-Allow-Origin: *');  
$url = $_POST['pagina']

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch, CURLOPT_MAXREDIRS, 1);

//Define um User-agent
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 5.1; rv:21.0) 
Gecko/20100101 Firefox/21.0');

curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);

//Não retorna a resposta
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

//Resposta
$data = curl_exec($ch);

if($data === false) {
echo 'Offline, detalhes do erro: ' . curl_error($ch);

} else {
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

if ($httpcode >= 200 && $httpcode < 300) {
    echo 'Online';
    $status = 'Online';
} else {
    echo 'Site Offiline, Ou Página não encontrada. Erro HTTP: ' . $httpcode;
    $status = 'Offline';
}
}");

Good returning to LINE 36 identified that the error is occasioned because of this section below that is in the code:

$url = $_POST['pagina']

When I remove this part above I can create and write to the file normally. someone has the solution ?

  • The ; along those lines

  • Thanks. But it made no difference :/ errk continues

1 answer

1


I think this is happening because the string you are writing in the file has PHP variables that are being interpreted, try to replace '$' with another character, then when you are reading the file you replace it with '$' again.

In PHP you can concatenate in two ways:

1) "Nome: $nome"

2) "Nome:" . $nome

I think that’s the problem, I tested replacing here and it worked.

Browser other questions tagged

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