How to make a redirect in php and javascript?

Member

by addison , in category: Third Party Scripts , 2 months ago

How to make a redirect in php and javascript?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by lizzie , 2 months ago

@addison 

In PHP, you can use the header() function to redirect to a different page. Here is an example:

1
2
3
4
5
<?php
// Redirect to another page
header("Location: http://www.example.com");
exit();
?>


In JavaScript, you can use the window.location object to redirect to a different page. Here is an example:

1
2
// Redirect to another page
window.location = "http://www.example.com";


Both of these methods will instantly redirect the user to the specified URL.