Sometimes you need to redirect your visitors to another page according to information they have entered in a form, or, if you changed an address in your site, you may need to detect a string in the old address and then redirect your visitors to the new address.
This code detects a value called “whatever” and redirects accordingly:
<?php if (array_key_exists('whatever', $_GET)) {
if ($_GET['whatever'] === '1') {
header('Location: https://www.thefreewindows.com');
}
else if ($_GET['whatever'] === '2') {
header('Location: https://www.thefreewindows.com/freeware-categories/');
}
}
?>
And, if you want a permanent redirect add the following line:
header( "HTTP/1.1 301 Moved Permanently" );
Related Posts:
- PHP code to detect if a visitor uses the default, query based, Wordpress permalink structure
- Query your monitor(s) directly and get infomation with Monitor Asset Manager
- Learn PHP reading and searching a free PHP Reference book
- Edit PHP, HTML, CSS, JS, with Codelobster PHP Edition
- Redirect automatically a web page to a URL of your choice, with Redirector Chrome Extension
- Query and manage Microsoft and MySQL databases with FreeSQL
- SQL PHPMyAdmin query to delete all posts in a Wordpress Category
- Run Apache, MySQL, PHP on Windows, even along with IIS, using XAMPP or WampServer
- QuickPHP lightweight standalone PHP web server to test and debug scripts
- Download phpBB free PHP bulletin board
- Test Wordpress, PHP, MYSQL and more on a Windows machine, with MS Web Platform Installer
- Edit HTML files easily, even with PHP code, using DFM2HTML WYSIWYG editor