PDA

View Full Version : Is it possible to use SERVER variables in templates?


JamesAB
01-06-2017, 02:51 PM
I'm looking to do something like this PHP code:
if ($_SERVER['SERVER_PORT'] != 443) {
header("HTTP/1.1 301 Moved Permanently");
header("Location: https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
exit();
}

But I would prefer to put it in individual templates because I only want to use it on a few pages.

Is there a "template friendly" version for similar code?
Or do I have to find a hook to place this sort of thing in?

Dave
01-06-2017, 02:59 PM
So you're looking to do the redirect in the template? I wouldn't recommend doing that since you have to rely on the meta redirect tag or a JavaScript redirect which is worse than a normal redirection through a header.

JamesAB
01-06-2017, 03:12 PM
Thanks for the advice?

What would be the best hook location to try to do something similar via PHP?

I need to compare variables to determine if the user is a guest and also what script/page they are viewing before determining to redirect to https or not.

Dave
01-06-2017, 03:33 PM
Try the hook "init_startup", that should be the first hook in vBulletin to be executed.