The following PHP code below checks the user agent property of the current website visitor. If the visitor is not a known search engine user agent, php code echos or runs JavaScript code that redirects to the desired newUrl after X number of seconds.
While the redirect to the new url can be accomplished without JavaScript, by creating a pause within the PHP code via php built in function sleep()
, for example sleep(5) causes a 5 seconds pause
function, the problem is that the web page won't load or doing anything until the number of seconds pause has elapsed leaving the website visitor just hanging there waiting for something to happen. This may result in the visitor abandoning your website altogether.
By echoing the JavaScript pause and redirect function, the webpage loads immediately as expected and when x number of seconds [secondsPause] has elapsed, the JavaScript code will cause the page redirect to page [redirectUrl].