谷歌二维码没有生成

时间:2014-03-20 15:32:10

标签: php html css authentication qr-code

我正在使用Google身份验证器处理身份验证表单。 当用户第一次登录时,会生成QR码。 QR码应该在我的页面上可见。 问题是当我从url栏浏览链接时,只能生成QR码,从url重定向不生成代码。这个问题有解决办法吗?

以下是可在Google身份验证器中找到的用于生成QR码的代码:

public function getUrl($user, $hostname, $secret) {
    $url =  sprintf("otpauth://totp/%s@%s?secret=%s", $user, $hostname, $secret);
    $encoder = "https://www.google.com/chart?chs=200x200&chld=M|0&cht=qr&chl=";
    $encoderURL = sprintf( "%sotpauth://totp/%s@%s%%3Fsecret=%s",$encoder, $user, $hostname, $secret);
    return $encoderURL;     
    }

这是我请求网址的地方:

<?php
    $linkQR = $g->getUrl($user,$location,$secret);
?>
<a  href="<?php echo $linkQR;?>"><img style="border: 0; padding:10px" src="<?php echo $linkQR;?>"/></a>

1 个答案:

答案 0 :(得分:0)

我找到了解决问题的方法。 在网址中使用https://chart.googleapis.com/代替https://www.google.com/来生成解决方案。 现在我的代码是在第一页加载时生成的。