Search code examples
phpjavascriptback

PHP: Browser go back a page


I want for something like this:

<?php
if($something)
    header('Location:javascript:history.go(-2)');
?>

but header('Location:javascript:history.go(-2)'); doesn't work. Any alternatives?

I don't know the page the user was just on, so I can't hardcode the url.


Solution

  • From your point of view, i think you might be looking for something like this:

    <html><head></head><body>
    <?php
    if($something){
    ?>
    <script type="text/javascript">
    window.history.go(-2);
    </script>
    <?php
    }
    ?>
    </body></html>