html 在php中获取完整的URL,没有白色

gwbalxhn  于 2023-03-21  发布在  PHP
关注(0)|答案(3)|浏览(101)

我尝试使用移动的浏览器将完整的URL从我的网站共享到whatsapp,我尝试了这个方法来检索完整的URL,当我回显变量时,它工作得很好,但当我使用移动浏览器共享时,它给我的链接白色,如下所示:一个40
无法打开,我如何才能得到完整的回声链接没有空格?

<?php
    $alink= (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ?

            "https" : "http") . "://" . $_SERVER['HTTP_HOST'] .

        $_SERVER['REQUEST_URI'];
    ?>
    

//To Share
    <a href="whatsapp://send?text=<?php echo $message['title'] ?> <?php echo "\r\n" ?> <?php echo $alink ?> <?php echo "\r\n" ?> <?php echo $myText ?>"
                           data-action="share/whatsapp/share">Share To Whatsapp</a>
monwx1rj

monwx1rj1#

$alink = str_replace(' ', '', $alink)

Manual

v2g6jxz6

v2g6jxz62#

获取完整的网址由javascript与window.location.href iny我的file.php

...
<div id="url"></div>
...
<script type="text/javascript">
   document.querySelector('#url').innertHTML = window.location.href
</script>
l3zydbqr

l3zydbqr3#

标准条件[$_SERVER['HTTPS'] == 'on']在负载平衡器后面的服务器上不起作用:

$isSecure = false;
    if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
        $isSecure = true;
    }
    elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') {
        $isSecure = true;
    }
    $REQUEST_PROTOCOL = $isSecure ? 'https' : 'http';

    echo $REQUEST_PROTOCOL."://".$_SERVER['HTTP_HOST'];

相关问题