I am trying to put a php code into a php variable and then write it to a file. But it does not work. Since it contains tabs, ][? space, new line etc. I tried to use EOD did not work.
Here is my code:
<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
$content02 = "\n";
$content01 = <<<EOD
<?php session_start();
if(!isset($_SESSION["UserData"]["Username"])){
header("location:login.php");
exit;
}
?>
EOD;
$content03='<!DOCTYPE html><html><head><title>Spambox</title></head><body><html dir="rtl"></html><form action="flushsink.php" method="get"><input type="submit" value="Flush!"></form>';
$content4 = $content01.$content02.$content03;
function writeUTF8File($filename,$content) {
$f=fopen($filename,"w");
fwrite($f,$content);
fclose($f);
}
writeUTF8File("spams.php",$content4);
header('Location: http://targeturl.com/int/spams.php');
?>
So basically I am flushing a spams.php file with new php code. But I can not write the php code to the file properly.
If I change the line 5 to :
$content01 = '<?php session_start(); if(!isset($_SESSION["UserData"]["Username"])){ header("location:login.php"); exit;}?>';
The application will write to the spams.php but the redirection (header()) does not work any more.
Any idea to put multiple line values containing php code to a variable?