jasonv1981 Posted September 19, 2010 Share Posted September 19, 2010 Hello, I am new to some of the rules to PHP as far as what you can POST or SEND via forms in PHP. I am attempting to change the location of a page via the header() function and basically redirect to another page if the weather is inclimate at an outdoor events center. Currently what I have is two different submit buttons that would post the header() redirect based on if the weather is good or bad. Ex. <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> Then the processing for the form is this file - <?php if(isset($_POST['weather_good'])){ $myFile = "../myfile.php"; $fh = fopen($myFile, 'w') or die("can't open file"); $stringData = echo "<?php header ('Location:fall_festival/index.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:fall_festival/weather/index.php');" ; $stringData = $link; fwrite($fh, $stringData); fclose($fh); echo "Page Updated"; } ?> The file doesn't return an error when it's processed but it also doesn't update the file header and redirect to the proper page. Thanks for your time and help! Quote Link to comment https://forums.phpfreaks.com/topic/213782-posting-a-new-header-to-redirect-page/ Share on other sites More sharing options...
trq Posted September 19, 2010 Share Posted September 19, 2010 I'm not sure what you are trying to do but all you are doing is writing the header() call to the file you are creating. Your code makes no attempt to actually redirect. Quote Link to comment https://forums.phpfreaks.com/topic/213782-posting-a-new-header-to-redirect-page/#findComment-1112721 Share on other sites More sharing options...
jasonv1981 Posted September 19, 2010 Author Share Posted September 19, 2010 Is that because I am using echo? What would I use to actually write the code to the file I am attempting to edit? Like CURL or setting an array prior to sending the header? Thanks for your response. Quote Link to comment https://forums.phpfreaks.com/topic/213782-posting-a-new-header-to-redirect-page/#findComment-1112804 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.