I am new to some of the functions of the PHP header(). I have used it to redirect pages in the past, but currently I am attempting to develop a page that can display a message from a submit button but that basically redirects the index page of a subfolder to a different index page in a different subfolder to relay information that a current business is closed due to inclimate weather.
So basically the admin area of the site would contain two submit buttons, one that says the weather is good which means that it is the normal index page and one that says the weather is bad and they are closed till further notice. Both submit buttons would have a POST function attached, but I do not understand how to get the file I am attempting to edit to open and then to write in the new header location.
Here is some of my code -
Code: Select all
<div style="width:220px; height:50px;">
<form method="POST" action="../../weather.php">
<input type="submit" value="Good Weather" name="weather_good" /> <input type="submit" value="Bad Weather" name="weather_bad" />
</form>
</div>Code: Select all
<?php
if(isset($_POST['weather_good'])){
$myFile = "../myfile.php";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = echo "<?php header ('Location:the_location/page_redirect.php'); ?>";
fwrite($fh, $stringData);
fclose($fh);
echo "Page Updated";
}
else if(isset($_POST['weather_bad'])){
$myFile = "../myfile.php";
$fh = fopen($myFile, 'w') or die("can't open file");
$link = "header('Location:the_location/page_redirect.php');" ;
$stringData = $link;
fwrite($fh, $stringData);
fclose($fh);
echo "Page Updated";
}
?>