How to redirect to the same page in PHP

前端 未结 9 1669
春和景丽
春和景丽 2020-12-01 03:46

How can I redirect to the same page using PHP?

For example, locally my web address is:

http://localhost/myweb/index.php

How can I r

9条回答
  •  时光说笑
    2020-12-01 04:21

    To really be universal, I'm using this:

    $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' 
        || $_SERVER['SERVER_PORT'] == 443) ? 'https://' : 'http://';
    header('Location: '.$protocol.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
    exit;
    

    I like $_SERVER['REQUEST_URI'] because it respects mod_rewrite and/or any GET variables.

    https detection from https://stackoverflow.com/a/2886224/947370

提交回复
热议问题