I have a page which,
If a variable is set(in a session) it will do an action, then it unsets the session.
Now it has to refresh itself.
This is where i am stuck.
Is there a way to get the exact url to the current page?
or is there a function to do this?
so header('location: ???');
header('Location: '.$_SERVER['REQUEST_URI']);
PHP refresh current page
With PHP code:
<?php
$secondsWait = 1;
header("Refresh:$secondsWait");
echo date('Y-m-d H:i:s');
?>
Note: Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP.
if you send any output, you can use javascript:
<?php
echo date('Y-m-d H:i:s');
echo '<script type="text/javascript">location.reload(true);</script>';
?>
When this method receives a true value as argument, it will cause the page to always be reloaded from the server. If it is false or not specified, the browser may reload the page from its cache.
Or you can explicitly use "meta refresh" (with pure html):
<?php
$secondsWait = 1;
echo date('Y-m-d H:i:s');
echo '<meta http-equiv="refresh" content="'.$secondsWait.'">';
?>
Greetings and good code,
$_SERVER['REQUEST_URI']
should work.
Another elegant one is
header("Location: http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]");
exit;
header('Location: '.$_SERVER['PHP_SELF']);
will also work
Source: Stackoverflow.com