I have this PHP code to write add a keyword to the end of a robots.txt file.
My web page gets an alert message saying that the keyword was successfully added to robots.txt.
However the contents of the actual robots.txt never changes.
What the hell?
I am at a loss to figure out what is happening here.
Any suggestions?
My web page gets an alert message saying that the keyword was successfully added to robots.txt.
However the contents of the actual robots.txt never changes.
What the hell?
I am at a loss to figure out what is happening here.
Any suggestions?
Code:
if (isset($_POST["submit_ban_keyword"]))
{
/*
file_put_contents does not work and does not throw an error.
*/
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$strRobotsFileName = DoGetParentOrCurrentDir() . "robots.txt";
$fileRobots = @fopen($strRobotsFileName, "r");
$arrayLines = [];
if ($fileRobots !== false)
{
while (!feof($fileRobots))
$arrayLines[] = fgets($fileRobots);
array_unshift($arrayLines, "User-agent: " . $_POST["text_keyword"]);
fclose($fileRobots);
$fileRobots = @fopen($strRobotsFileName, "w");
if ($fileRobots !== false)
{
for ($nI = 0; $nI < count($arrayLines); $nI++)
{
fputs($fileRobots, $arrayLines[$nI] . PHP_EOL);
}
if (fclose($fileRobots) === true)
PrintJavascriptLine("alert(\"'" . $_POST["text_keyword"] . "' was added to banned list in the file robots.txt...\")", 1, true);
else
DoAlertLastError();
}
else
DoAlertLastError();
}
else
DoAlertLastError();
}