Jump to content

header form then redirect fails


muppet77

Recommended Posts

hi, i am attempting to use a form to submit info which then determines a redirection to one of 2 urls.

 

i can get the form appearing and submitting but the redirect doesn't happen.

 

can someone please help?

 

thanks in advance

 

<?php

  if (!isset($_POST['submit'])) { // if page is not submitted to itself echo the form
?>
<html>
<head>
<title>corners in running</title>
</head>
<body>
<form method="post" action="<?php echo $PHP_SELF;?>">

Corners:<br />
10:<input type="radio" value="10" name="wholecorners">
11:<input type="radio" value="11" name="wholecorners"><br />

<input type="submit" value="submit" name="submit">
</form>

<?php

$corners = $_POST["wholecorners"];

if($corners>=10 && $corners<=10.99) {header('Location: http://maidenerleghweather.com/corners1.php?var1=' .  $corners. '&var2='.$time ); }

if($corners>=11 && $corners<=11.99) {header('Location: http://maidenerleghweather.com/corners2.php?var1=' .  $corners. '&var2='.$time ); }

}


?>

Link to comment
https://forums.phpfreaks.com/topic/268149-header-form-then-redirect-fails/
Share on other sites

Try the following:

 

<html>
<head>
<title>corners in running</title>
</head>
<body>
<form method="post" action="<?php echo $PHP_SELF."?post";?>">

Corners:<br />
10:<input type="radio" value="10" name="wholecorners">
11:<input type="radio" value="11" name="wholecorners"><br />

<input type="submit" value="submit" name="submit">
</form>

<?php
if($_POST['submit'] && isset($_GET['post'])) {
$corners = $_POST["wholecorners"];

if($corners>=10 && $corners<=10.99) {header('Location: http://maidenerleghweather.com/corners1.php?var1=' .  $corners. '&var2='.$time ); }
if($corners>=11 && $corners<=11.99) {header('Location: http://maidenerleghweather.com/corners2.php?var1=' .  $corners. '&var2='.$time ); }

}

?>

Code is not tested!

 

 

It should, if i remember right, only redirect you if the submit button has been activated, and extra secure by setting a ?post in the URL.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.