PHP:URL中不存在值时,使用$ _GET ['value']错误

时间:2018-11-29 20:35:46

标签: php get

我正在尝试在PHP联系人表单发送电子邮件并重定向到上一页后显示一条简单的确认消息。 我这样重定向:

header("Location: contact.php?mailsend");

在contact.php中,我试图以这种方式显示确认信息:

<?php 
  $mailsend = $_GET['mailsend'];
  if ($mailsend == 1){
      echo "<div><p>Your e-mail was sent.</p></div>";
  }
?>

但是,只有在URL中存在mailsend时,页面才能正确加载。如果不是,则该页面不会加载(显示我的CMS错误页面)。

我在做什么错了?

更新

按照注释中的建议,将我的php包装在isset语句中:

<?php 
  if (isset($_GET['mailsend'])) {
    $mailsend = $_GET['mailsend'];
    if ($mailsend == 1){
        echo "<div><p>Your e-mail was sent.</p></div>";
    }
  }
?>

即使URL包含mailsend=1

,该页面也不再引发错误,而且也从不显示确认信息

0 个答案:

没有答案