gpt4 book ai didi

php - 检查表单提交的 URL 是否有 HTTPS

转载 作者:太空宇宙 更新时间:2023-11-03 13:22:50 25 4
gpt4 key购买 nike

我有一个脚本可以检查当前页面是否存在 SSL,但我需要它工作,所以当用户在表单中输入 URL 并单击提交按钮时,它会返回"is"“您拥有的 URL”输入有 SSL”,或者如果没有则返回“此站点没有 SSL”。

这是我的 PHP 代码:

if ( !empty( $_SERVER['HTTPS'] ) ) {
echo "<p>This page does not have SSL. It would be worth adding SSL to this website as it's a ranking factor</p>";
}else{
echo '<p>Good job, this page has SSL.</p>';
}

提前致谢。

最佳答案

您似乎允许用户查看他们的网站,基于此,您可以使用:

$url = parse_url( 'https://user.url' );
if( $url['scheme'] == 'https' )
{
echo '<p>Good job, this page has SSL.</p>';
}else{
echo "<p>This page does not have SSL. It would be worth adding SSL to this website as it's a ranking factor</p>";
}

旧答案 - 不适用于 OP 的答案,但可用于检查当前 URL 是否使用 HTTPS:

if ( $_SERVER['REQUEST_SCHEME'] == "https" )
{
echo '<p>Good job, this page has SSL.</p>';
}else{
echo "<p>This page does not have SSL. It would be worth adding SSL to this website as it's a ranking factor</p>";
}

您还可以使用:

if ( isset($_SERVER['HTTPS']) && 'on' === $_SERVER['HTTPS'] )
{
echo '<p>Good job, this page has SSL.</p>';
}else{
echo "<p>This page does not have SSL. It would be worth adding SSL to this website as it's a ranking factor</p>";
}

最后一个选项似乎是确定 https 的最安全方法。

关于php - 检查表单提交的 URL 是否有 HTTPS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44035902/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com