在使用SSL之后,我是否需要向PHP添加任何代码

在使用SSL之后,我是否需要向PHP添加任何代码,php,ssl,https,Php,Ssl,Https,我正在使用PHP在我的网站上使用一个简单的联系表单,我将在我的网站上安装SSL,代码方面我是否需要对PHP代码进行任何更改,我对SSL完全陌生,这是我第一次安装SSL <?php $errors = array(); $missing = array(); if (isset($_POST['send'])) { $to = 'john@example.com'; $subject = 'Feedback from contact form'; $expected = array('nam

我正在使用PHP在我的网站上使用一个简单的联系表单,我将在我的网站上安装SSL,代码方面我是否需要对PHP代码进行任何更改,我对SSL完全陌生,这是我第一次安装SSL

<?php
$errors = array();
$missing = array();
if (isset($_POST['send'])) {
$to = 'john@example.com';
$subject = 'Feedback from contact form';
$expected = array('name', 'email', 'comments');
$required = array('name', 'email', 'comments');
$headers = "From: webmaster@example.com\r\n";
$headers .= "Content-type: text/plain; charset=utf-8";
require './includes/mail_process.php';
    if ($mailSent) {
    header('Location: thanks.php');
    exit;
}
}
?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Contact Us</title>
<link href="./styles.css" rel="stylesheet" type="text/css">
</head>

<body>
<h1>Contact Us</h1>
<?php if ($_POST && $suspect) { ?>
<p class="warning">Sorry your mail could not be be sent.</p>
<?php } elseif ($errors || $missing) { ?>
<p class="warning">Please fix the item(s) indicated.</p>
<?php }?>
<form name="contact" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<p>
    <label for="name">Name:
    <?php if ($missing && in_array('name', $missing)) { ?>
    <span class="warning">Please enter your name</span>
    <?php } ?>
    </label>
    <input type="text" name="name" id="name"
    <?php
    if ($errors || $missing) {
        echo 'value="' . htmlentities($name, ENT_COMPAT, 'utf-8') . '"';
    }
    ?>
    >
</p>
<p>
    <label for="email">Email:
    <?php if ($missing && in_array('email', $missing)) { ?>
    <span class="warning">Please enter your email address</span>
    <?php } elseif (isset($errors['email'])) { ?>
    <span class="warning">Invalid email address</span>
    <?php } ?>
    </label>
    <input type="text" name="email" id="email"
    <?php
    if ($errors || $missing) {
        echo 'value="' . htmlentities($email, ENT_COMPAT, 'utf-8') . '"';
    }
    ?>
    >
</p>
<p>
    <label for="comments">Comments:
    <?php if ($missing && in_array('comments', $missing)) { ?>
    <span class="warning">You forgot to add your comments</span>
    <?php } ?>
    </label>
    <textarea name="comments" id="comments"><?php 
    if ($errors || $missing) {
        echo htmlentities($comments, ENT_COMPAT, 'utf-8');
    }
    ?></textarea>
</p>
<p>
    <input type="submit" name="send" id="send" value="Send Comments">
</p>
</form>
<pre>
</body>
</html>

联系我们
联系我们

很抱歉,您的邮件无法发送

请修复所示项目


因为您没有任何绝对URL引用,所以不会有问题。我建议你把它放在你的标题中(或者放在你所有PHP文件的顶部),以强制他们使用https,这样如果你的网站中确实需要绝对URL,你可以让他们都使用https,因为每个人都会被强制使用


您必须将绝对URL更改为“https://....". 如果您没有使用绝对URL,那么如果您的表单和处理脚本都在https上,则没有什么可以更改的

如果我在页面上使用绝对URL,你可以强制使用https,如果你需要绝对URL,你可以让它们成为https,而不用担心。请参阅我的编辑。
<?php
$suspect = false;
$pattern = '/Content-Type:|Bcc:|Cc:/i';

function isSuspect($val, $pattern, &$suspect) {
if (is_array($val)) {
    foreach ($val as $item) {
        isSuspect($item, $pattern, $suspect);
    }
} else {
    if (preg_match($pattern, $val)) {
        $suspect = true;
    }
}
}

isSuspect($_POST, $pattern, $suspect);

if (!$suspect) {
foreach ($_POST as $key => $value) {
    $temp = is_array($value) ? $value : trim($value);
    if (empty($temp) && in_array($key, $required)) {
        $missing[] = $key;
        $$key = '';
    } elseif(in_array($key, $expected)) {
        $$key = $temp;
    }
}
}

if (!$suspect && !empty($email)) {
$validemail = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL);
if ($validemail) {
    $headers .= "\r\nReply-to: $validemail";
} else {
    $errors['email'] = true;
}
}

if (!$suspect && !$missing && !$errors) {
$message = '';
foreach ($expected as $item) {
    if (isset($$item) && !empty($$item)) {
        $val = $$item;
    } else {
        $val = 'Not selected';
    }
    if (is_array($val)) {
        $val = implode(', ', $val);
    }
    $item = str_replace(array('_', '-'), ' ', $item);
    $message .= ucfirst($item) . ": $val\r\n\r\n";
}
$message = wordwrap($message, 70);

$mailSent = mail($to, $subject, $message, $headers, $authenticate); 
if (!$mailSent) {
    $errors['mailfail'] = true;
}
}
if($_SERVER['HTTPS'] != 'on' || !stristr($_SERVER['HTTP_HOST'], 'www.')) {
    $redirect= "https://www.".str_replace('www.','',$_SERVER['HTTP_HOST']).$_SERVER['REQUEST_URI'];
    header("Location:$redirect");
}