-1

I want when entered in input box, page refresh according to the entered value.
Actually enter the number 2 when I refresh the page twice.
This is my code, however, my code runs only once.

<?php
if(isset($_POST['refresh-time'])){  
    $_SESSION['value'] = $_POST['refresh-time'];
    for( $i = 0 ; $i < $_SESSION['value'] ; $i++ ){
        $value = $_SESSION['value'];
        $url = $_SERVER['REQUEST_URI'];
        header("Refresh: $value ; URL=$url");
    }

}
?>

<form class="form-inline" method="POST">
<div class="form-group">
    <label for="text">referesh number</label>
    <input type="text" class="form-control" name="refresh-time">
</div>  
<button type="submit" class="btn btn-default"><i class="fa fa-pencil" ></i> apply</button>
</form>
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
noovin
  • 27
  • 4

1 Answers1

0

First, you should use

header("Refresh: {$value} ; URL={$url}");

or

header("Refresh:" . $value ." ; URL=" .$url);

but, you use the $_SESSION['value'] value only when posted a new one, and then you are overwriting the $_SESSION['value'] everytime, so why use $_SESSION?

Also, if the headers are already set (something was "printed") this is not going to work. I don't understand de use of this code, but anyway, a javascript approach would be better.

window.location.href = "<?php echo $url;?>";
Alex Angelico
  • 3,710
  • 8
  • 31
  • 49