jdborg jdborg - 6 months ago 50
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 &).

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