etrader Posted September 8, 2009 Share Posted September 8, 2009 How can I automatically redirect a page to another url by php, when having a tracking code like Google Analytics. header( 'Location: http://www.yoursite.com/new_page.html' ) ; works well, but then it does not read the php tracking code. Quote Link to comment https://forums.phpfreaks.com/topic/173484-redirecting-by-php/ Share on other sites More sharing options...
Alex Posted September 8, 2009 Share Posted September 8, 2009 You would have to use a meta tag redirect and set it to like 1 second. This is because the JavaScript doesn't send the information to Google Analytics until after/during the page is loading. Which doesn't occur if you're php header('Location:'); Quote Link to comment https://forums.phpfreaks.com/topic/173484-redirecting-by-php/#findComment-914470 Share on other sites More sharing options...
bundyxc Posted September 8, 2009 Share Posted September 8, 2009 I believe if you set it to zero seconds it will wait until the full page has loaded. Quote Link to comment https://forums.phpfreaks.com/topic/173484-redirecting-by-php/#findComment-914520 Share on other sites More sharing options...
etrader Posted September 8, 2009 Author Share Posted September 8, 2009 I also have chance to add php tracking codes without any javascript; thus a pure php code in php.index; but the problem is that header('Location:'); should be the first line, otherwise it gives error ... is there any similar command which can be placed at bottom of a page ? Quote Link to comment https://forums.phpfreaks.com/topic/173484-redirecting-by-php/#findComment-914539 Share on other sites More sharing options...
TeNDoLLA Posted September 8, 2009 Share Posted September 8, 2009 You have to design your program structure the way that header calls/modifications will be done in the beginning based on actions when needed. Or use buffer (http://fi.php.net/manual/en/ref.outcontrol.php). Quote Link to comment https://forums.phpfreaks.com/topic/173484-redirecting-by-php/#findComment-914622 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.