【问题标题】:Internal Server Error when submitting a page提交页面时出现内部服务器错误
【发布时间】:2016-02-02 07:09:35
【问题描述】:

我正在开发一个门户网站。在这里我忘记了密码页面。在这个忘记密码页面将有一个带有电子邮件 ID 的表格。当用户提供他的电子邮件并单击提交时,它将发送一封电子邮件。

但现在实际问题出在我的本地主机上,它工作正常。但是当我上传到服务器时。当我打开页面忘记密码并提供电子邮件 ID 并单击提交时,它显示内部服务器错误,如下图所示。

而我写的代码是

<?php 
ini_set('display_errors', 1);
include 'header-employer.php';
echo "In forget password page";

?>
<script type="text/javascript">
function valid_details()
{
    var con1=/^[a-zA-Z0-9\_\.]+\@[a-zA-Z\.]+\.([a-z]{2,4})$/;

    if(document.getElementById('email').value=="")
    {
        alert("Please Enter Email Id");
        document.getElementById('email').focus();
        return false;
    }
    else if(!document.getElementById('email').value.match(con1))
    {
        alert("Enter Valid Email Id");
        document.getElementById('email').focus();
        return false;
    }
    if(document.getElementById('pass').value=="")
    {
        alert("Please Enter Password");
        document.getElementById('pass').focus();
        return false;
    }
}
</script>

<?php
if(isset($_POST['sub']) && $_POST['sub']=="Submit")
{
    echo "entered into forget password";
    $email=mysql_real_escape_string(trim($_POST['email']));
    echo "email in forget pwd page:".$email;
    $email_fetch=$con->getdata("select * from employers where email='{$email}'");
    $rows=mysql_num_rows($email_fetch);
    print_r($rows);
    if($rows==0)
    {
        echo '<script> alert("Email Id Not Registered With Us.") </script>';
    }
    else
    {
        function randomcode()
            {
                $chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz0123456789";
                $i = 0;
                $vcode = '' ;
                while($i < 7)
                {
                    $num = mt_rand(0,61);
                    $tmp = substr($chars, $num, 1);
                    $vcode = $vcode . $tmp;
                    $i++;
                }
                return $vcode;
            }
            $msg=randomcode();
            $secure_msg=md5($msg);
            echo "update employers set pass='$secure_msg' where email='{$email}'";
            $update_pass=$con->setdata("update employers set pass='$secure_msg' where email='{$email}'");

                        $user_subject='Your New Password';
                        $user_message='
                        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<meta name="viewport" content="width=device-width"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Job Portal</title>
<!-- <link rel="stylesheet" type="text/css" href="stylesheets/email.css"/> -->
</head>
<body bgcolor="#FFFFFF">

<table style="width:100%;" bgcolor="#999999">
<tr>
<td></td>
<td>
<div style="padding:15px;max-width:600px;margin:0 auto;display:block;">
<table style="width:100%;" bgcolor="#999999">
<tr>
<td style="padding:15px;"><img src="http://www.jobwhizz.com/images/logo.jpg"/></td>
</tr>
</table>
</div>
</td>
<td></td>
</tr>
</table> 

<table style="width: 100%;">
<tr>
<td></td>
<td style="display:block!important;max-width:600px!important;margin:0 auto!important;clear:both!important;" bgcolor="#FFFFFF">
<div style="padding:15px;max-width:600px;margin:0 auto;display:block;">
<table style="width:100%;">
<tr>
<td>
<h3>Dear User,</h3>
<p>Your password was reset at <a style="color: #2BA6CB;" href=http://www.jobwhizz.com target=_blank>www.jobwhizz.com</a>
</p>

<p style="padding:15px;background-color:#ECF8FF;margin-bottom: 15px;">
New password is '.$msg.'
</p>

<table style="background-color:#ebebeb;font-size:18px;line-height:19px;font-family: Helvetica, Arial, sans-serif; font-weight:normal;" width="100%">
<tr>
<td>

<table align="left" style="width: 200px;float:left;">
<tr>
<td style="padding-left: 10px;">
<h5 class="">Connect with Us:</h5>
<p class=""><a href="#" style="padding: 3px 7px;font-size:12px;margin-bottom:10px;text-decoration:none;color: #FFF;font-weight:bold;display:block;text-align:center;background-color: #3B5998!important;">Facebook</a> <a href="#" style="padding: 3px 7px;font-size:12px;margin-bottom:10px;text-decoration:none;color: #FFF;font-weight:bold;display:block;text-align:center;background-color: #1daced!important;">Twitter</a> <a href="#" style="padding: 3px 7px;font-size:12px;margin-bottom:10px;text-decoration:none;color: #FFF;font-weight:bold;display:block;text-align:center;background-color: #DB4A39!important;">Google+</a></p>
</td>
</tr>
</table> 

<table align="right" style="width: 300px;float:right;">
<tr>
<td>
<h5 class="">Contact Info:</h5>
<p>Phone: <strong>408.341.0600</strong><br/>
Email: support@jobwhizz.com</td>
</tr>
</table> 
</td>
</tr>
</table> 
</td>
</tr>
</table>
</div> 
</td>
<td></td>
</tr>
</table> 

</body>
</html>
                        ';
                        echo "sending email";
                        $mailto_user=mail($email, $user_subject, $user_message, $headers);

                        //var_dump($mailto_user);
                        if($mailto_user)
                        {
                            echo '<script> alert("A New Password Is Sent To Your Email Id") </script>';
                            //echo "<script>window.location.href = 'employer-signin.php';</script>";
                            header('location: employer-signin.php');
                        }
    }
}           
?>
<div class="mainwallpaper">
<div class="container">
<div class="col-md-offset-1 col-md-5"><span class="spacer100"></span>
<div class="transparent panel panel-default" >
<div class="transparent panel panel-body">
<p style="align:center;font-weight:700;">Forgot Password ?</p><hr/>
<form class="form-horizontal" method="post" action="" onsubmit="return valid_details();" autocomplete="off">
  <div class="form-group">

    <div class="col-sm-12">
        <label for="inputPassword3" class=" control-label">Your Registered Email Id</label>
        <span class="spacer10"></span>
      <input type="text" class="form-control" name="email" id="email" placeholder="Registered Email Id">
      <span class="spacer10"></span>
      <input type="submit" class="btn btn-warning" name="sub" value="Submit">
    </div>
  </div>

</form>
</div>
</div>
</div>
</div>
</div>
<style>.mainwallpaper{background-image: url("http://jobwhizz.com/images/forget.jpg");
width:100%;background-size: cover;height:450px;background-position: 50% -60px;}
.layer{background-color:; width: 100%;    height: 100%;}
.transparent{background:rgba(255,255,255,0.3) !important;}
</style>
<?php include 'footer.php'; ?>

谁能帮帮我……

提前致谢......!

【问题讨论】:

  • 我认为您的 htaccess 文件有问题。
  • 尝试检查主机日志是否有错误,似乎您在共享主机上并且您的ini_set('display_errors', 1); 被忽略了您必须在主机控制面板中查找错误
  • error.log 文件中应该有一些日志。你能检查一下吗?如果没有error.log文件,则应逐行调试代码。
  • 谢谢大家,我会检查的
  • 大家好,感谢您的回复,我找到了问题

标签: php internal-server-error


【解决方案1】:

您可以尝试以下几种方法。

  1. 尝试在脚本顶部添加error_reporting('E_ALL');
  2. 检查您的 Web 服务器的配置(htaccess、虚拟主机等)。
  3. (更可能的原因)由于您使用的是mail() 函数,因此可能会导致错误。检查服务器的邮件配置。更多信息:PHP's mail() function causes a 500 Internal Server Error only after a certain point in the code

  4. 将服务器配置与本地主机配置进行比较。

【讨论】:

  • 这对您解决问题有帮助吗?
  • No Vishwa 刚开始工作。你说 mail() 也会有问题。但是电子邮件正在进入我的垃圾邮件。
  • 嗨 Vishwa 是的,我发现这是由于邮件服务器造成的问题。因为当我注释掉电子邮件功能时,我只是打印了一条消息。现在,当我单击按钮时,它显示更新的状态和页面未显示 500 内部服务器错误。感谢您的回复.....!
  • 太棒了!很高兴它有帮助。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-05-23
相关资源
最近更新 更多