Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it good practise to use meta refresh tags for redirects instead of header() function in php?

I have to use redirects a lot in my scripts, for example after a user logs in I need to redirect them to the admin area, etc. But I find it inconvenient to always have to have the header function at the very top. So if I use the meta refresh tags for my redirects, is that something that would be frowned upon according to best practices or is it acceptable?

function redirect($location) {
    echo "<meta http-equiv='refresh' content='0; url=$location' />";
}
like image 564
Kent Avatar asked Dec 25 '10 05:12

Kent


1 Answers

No. The Wikipedia clearly states:

Meta refresh is a discouraged method of instructing a web browser to automatically refresh the current web page or frame after a given time interval.....

Meta refresh tags have some drawbacks:

  1. If a page redirects too quickly (less than 2-3 seconds), using the "Back" button on the next page may cause some browsers to move back to the redirecting page, whereon the redirect will occur again. This is bad for usability, as this may cause a reader to be "stuck" on the last website.
  2. A reader may or may not want to be redirected to a different page, which can lead to user dissatisfaction or raise concerns about security.
like image 80
shamittomar Avatar answered Nov 14 '22 23:11

shamittomar