jdborg jdborg - 1 year ago 145
HTML Question

Keeping URL parameters during PHP redirect

This isn't working:

header('Location: www.mysite.com/index.php?foo=bar&var=abc');

I end up with www.mysite.com/index.php?foo=bar I think HTML might be trying to interpret the &var as a character. The initial variable is passed (after ?) but all subsequent are not (after &).

Answer Source
if( isset($_SERVER['HTTPS'] ) ) {
  header('Location: https://'.$_SERVER['SERVER_NAME'].'/index.php?'.$_SERVER['QUERY_STRING']);
  header('Location: http://'.$_SERVER['SERVER_NAME'].'/index.php?'.$_SERVER['QUERY_STRING']);

use htmlspecialchars to prevent html injection

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download