Doubt fwrite writing to file

0

I have a problem writing a file using fwrite, I can create the file normally, however 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 have identified the problem here: fwrite ($ fp, "my code")

Well in there I have the following code that I need to insert inside 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';
}
}");

Well, going back to LINE 36, I identified that the error is caused 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. does anyone have the solution?

    
asked by anonymous 24.03.2018 / 15:26

1 answer

1

I think this is happening because the string you are writing in the file has PHP variables being interpreted, try replacing '$' with another character, then when you read the file you replaced with '$' again .

In PHP you can concatenate in two ways:

1) "Nome: $nome"

2) "Nome:" . $nome

I think that's the problem, I tried replacing it here and it worked.

    
29.03.2018 / 20:45