【问题标题】:500 Internal Error, Whats wrong with my code? [closed]500 内部错误,我的代码有什么问题? [关闭]
【发布时间】:2013-12-22 21:00:09
【问题描述】:

我的编码有点问题,当我运行这个脚本时,我不断收到 500 错误:

<?php
include_once("../../includes/connect.php");
if (isset($_POST['action']) && $_POST['action'] == "check"){
$email = mysql_real_escape_string(strip-tags($_POST['email']));
$username = mysql_real_escape_string(strip_tags($_POST['username']));

if (strpos($email,"@")!== false){
    $check_email = explode("@",$email);
    if (strpos($check_email[1],".")=== false){
        echo 3;
        exit();
    }
} else {
    echo 3;
    exit();
}
$email_query = mysql_query("SELECT id FROM users WHERE email='$email' LIMIT 1");
if (mysql_num_rows($email_query)== 1){
    //Email already exists
    echo 1;
    exit();
} else {
    $username_query = mysql_query("SELECT username FROM users WHERE username='$username' LIMIT 1");
    if (mysql_num_rows($username_query)== 1){
        //Username already exists
        echo 2;
        exit();
    } else {
        //Everything is fine
        echo 0;
        exit();
    }
}
}
if (isset($_POST['action']) && $_POST['action'] == "register"){
    $username = mysql_real_escape_string(strip_tags($_POST['username']));
    $password = mysql_real_escape_string(strip_tags($_POST['password']));
    $email = mysql_real_escape_string(strip_tags($_POST['email']));

    $activation_code = md5($username.$password);

    $reg_query = mysql_query("INSERT INTO users (username, password, email, activfation_code) VALUES ('$username', '".md5($password)."', '$email', '$activation_code')");
    if ($reg_query){
        //Successfully registered
        $new_userid = mysql_insert_id();
        //Create new users folder
        #mkdir("../users/$new_userid", 0755);
        //Create new users images folder
        #mkdir("../users/$new_userid/images", 0755);
        //Create new users media folder
        #mkdir("../users/$new_userid/media", 0755);

        $to = $email;
        $from = "noreply@atradiesinc.com";
        $subject = "Activate your Account!";

        $message = "<h3>Welcome to Atradies Inc Gaming Community, ".$username."!</h3>
        <p>To complete registration you must verify and activate your account. Click the link below and the magic shall happen.</p>
        <p><a href='http://www.atradiesinc.com/network/?id=$new_userid&activate=$activation_code'>http://www.atradiesinc.com/network/?id=$new_userid&activate=$activation_code</a></p>
        <p>Once your account has been activated, you may login and join in with the community with the details below:<br />
        <strong>Username: </strong>$username<br />
        <strong>Password: </strong><i>Password you supplied on registration</i></p>
        <p>Thank you and enjoy the community!</p>";

        $headers = 'MIME-Version: 1.0' . "\r\n";
        $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
        $headers .= "From: $from\r\nReply-To: $from";
        mail($to, $subject, $message, $headers);

        echo 1;
        exit();

    } else {
        //Registration failed
        echo 0;
        exit();
    }
}

?>

有什么问题?我似乎找不到任何问题。是代码,还是我正在尝试的服务器?我试过 Chrome Inspect Element 控制台,但它没有提供更多信息,然后是该文件的“500 Internal Server Error”。

谢谢!

【问题讨论】:

  • 查看您的网络服务器 error.log,或启用 PHP。
  • 检查您的服务器日志。错误出在服务器端,而不是浏览器端,因此 Chrome 的“检查元素”功能对您没有帮助。
  • 尝试将其添加到页面顶部:ini_set('display_errors', 1); error_reporting(-1);
  • 不推荐使用 mysql_* 函数 (php.net/manual/en/function.mysql-db-query.php),使用 mysqli_* - 你在 strip-tags($_POST['email']) 中有错字
  • $activation_code = md5($username.$password) 非常不安全。试试 $activation_code = md5(openssl_random_pseudo_bytes(8));

标签: php internal


【解决方案1】:

你在第三行有一点错别字:

$email = mysql_real_escape_string(strip-tags($_POST['email']));

应该是

$email = mysql_real_escape_string(strip_tags($_POST['email']));

看看 cmets,它们非常重要。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-02-11
    • 1970-01-01
    • 2023-04-01
    • 1970-01-01
    • 2014-12-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多