Jump to content

Posting A New Header to Redirect Page


jasonv1981

Recommended Posts

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.