PHP. Redirect to another page

I’ll give an example of redirecting to another page:

<?php
  header("Location: http://www.example.com/");
  exit;
?>

Example of redirecting in specified number of seconds:

<?php
  header('Refresh: 5; URL=http://www.example.com/');
  echo 'After 5 seconds you will be automatically redirected to another page.';
  exit;
?>

Example of Redirect in JavaScript (this may not work for everyone):

<script type="text/javascript">
  location.replace("http://www.example.com/");
</script>

Example Redirect in JavaScript after 5 seconds (this may not work for everyone):

<script type="text/javascript">
  setTimeout('location.replace("http://www.example.com/")', 5000);
</script>

An example of Redirect in HTML after 5 seconds (if you specify 0, it will redirect immediately):

<meta http-equiv="refresh" content="5; url=http://www.example.com/">

Leave a comment

Leave a Reply