简体   繁体   中英

how to redirect the user to the referer page

I have this part of my script

 <?php
     else:
 ?>
    <script>
        alert("You are not allowed to edit this CV!");
    </script>

 <?php
     echo '<meta http-equiv="refresh" content="1"; url="'.$the_class->settings[0]['DomainName'].'myresume.php"';
     endif;
 ?>

the objective is, after the alert box popped-out and the "ok" button was clicked, the user should be redirected to http://www.mydomain.com/myresume.php

now the problem is, before the page loads the redirection, the alert box keeps popping out without reaching the destination page at all...how to fix this ?

You can do something like this if you want to always send them back to http://www.mydomain.com/myresume.php :

<script>
   alert("You are not allowed to edit this CV!");
   window.location.href = 'http://www.mydomain.com/myresume.php';
</script>

You can do something like this if you instead want to send them back to whatever page they were on previously:

<script>
   alert("You are not allowed to edit this CV!");
   history.back();
</script>

the problem seems to be that you are trying to set a header after sending content.

You can try using the header function . If that does not work, you can simply remove the alert .

If you need to display the alert you can put a window.location in the script tag and remove the php part.

You can also experiment by turning the output buffering off using ob_implicit_flush .

How about sending them back using javascript:

<?php
     else:
 ?>
    <script>
        alert("You are not allowed to edit this CV!");
        document.location = 
<?php
        echo '"'.$the_class->settings[0]['DomainName'].'myresume.php"';
?>
    ;
    </script>

 <?php
     endif;
 ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM