Is there a way to redirects to the same page using PHP.??? I just need to reload or refresh the gridview. I don't need to redirect to a website or link, I need is redirect it to the same page or same form like main.php.
I already used the header(), but its not working to me and all I see is linking in the website.
Thanks.
Simply do:
$referer = $_SERVER['HTTP_REFERER'];
header("Location: $referer");
You should redirect with a location header after every post, because otherwise when the user presses the refresh button, it will send again the same form...
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
file_put_contents('data.txt', $_POST['data']);
header('location: ' . $_SERVER['PHP_SELF']);
} else {
header('content-type: text/html; charset=utf-8');
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"
enctype="application/x-www-form-urlencoded; charset=utf-8">
<input name="data" type="text" value="<?php echo file_get_contents('data.txt'); ?>"/>
<button>küldés</button>
</form>
<?php
}
Btw. if you want to do proper work, you should try out a php framework instead of this kind of spaghetti code...
Here are two example to redirect to a form. Lets say that your filename is main.php
<form action="main.php">
Name: <input type="text" name="name">
<input type="submit" name="submit" value="Submit">
</form>
Or you can use this
<form action="<?php echo $_SERVER['PHP_SELF']; ?>">
Name: <input type="text" name="name">
<input type="submit" name="submit" value="Submit">
</form>
Did that answer your question?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With