Instead of sending to random URLs (which is actually not a good idea), we recommend using redirects
Decision will be
<?php if (isset ($_SERVER['HTTP_REFERER']) ) { $url = htmlspecialchars($_SERVER['HTTP_REFERER'],ENT_QUOTES,'UTF-8'); echo '<br /><form action="redirect.php" method="get"> <input type="hidden" name="return" value="'.$url.'"> <div id="submit"><input type="submit" value="Return to previous page" /></div> </form>'; } ?>
then in redirect.php
<?php if (isset ($_GET['return'] ) { $url = $_GET['return']; header('Location: '.$url, true, 303); // or 302 for compatibility reasons echo '<a href="'.htmlspecialchars($url,ENT_QUOTES,'UTF-8').'">Continue</a>'; exit; }else{ echo 'Error, no redirect specified'; }
you can replace action="GET" and $_GET with action="POST" and $_POST , and it will work the same.
or simply
if (isset ($_SERVER['HTTP_REFERER']) ) { $url = htmlspecialchars($_SERVER['HTTP_REFERER'],ENT_QUOTES,'UTF-8'); echo '<a href="'.$url.'">Return to previous page</a>'; }
both will still create a new story in the browser.
source share