【问题标题】:Form processing causing apache to crash?表单处理导致 apache 崩溃?
【发布时间】:2011-04-02 08:43:09
【问题描述】:

我使用以下代码在我的网站上注册用户。问题是当用户注册时 apache 没有响应并崩溃。

我的代码有中断还是我做错了什么????

<?php

include ('../includes/db_connect.php');

$firstname = $_POST['firstname'];
$email = $_POST['email'];    
$username = $_POST['username'];
$password = md5($_POST['password']);

// lets check to see if the username already exists

$checkuser = mysql_query("SELECT username FROM users WHERE username='$username'");

$username_exist = mysql_num_rows($checkuser);

if($username_exist > 0){
    echo "I'm sorry but the username you specified has already been taken.  Please pick another one.";
    unset($username);
    //include 'register.html';
    exit();
}

// lf no errors present with the username
// use a query to insert the data into the database.

$query = "INSERT INTO users (firstname, email, username, password)
VALUES('$firstname', '$email', '$username', '$password')";
mysql_query($query) or die(mysql_error());
mysql_close();

echo "You have successfully Registered";

// mail user their information

//$yoursite = ‘www.blahblah.com’;
//$webmaster = ‘yourname’;
//$youremail = ‘youremail’;
//    
//$subject = "You have successfully registered at $yoursite...";
//$message = "Dear $firstname, you are now registered at our web site.  
//    To login, simply go to our web page and enter in the following details in the login form:
//    Username: $username
//    Password: $password
//    
//    Please print this information out and store it for future reference.
//    
//    Thanks,
//    $webmaster";
//    
//mail($email, $subject, $message, "From: $yoursite <$youremail>\nX-Mailer:PHP/" . phpversion());
//    
//echo "Your information has been mailed to your email address.";

?>

【问题讨论】:

  • Apache 的error.log 中的任何内容?崩溃究竟是什么样的?
  • 顺便说一下,您的脚本极易受到 SQL 注入的攻击。参见例如stackoverflow.com/questions/60174/…stackoverflow.com/questions/47087/…
  • 启动 Apache2.2 服务 Apache2.2 服务正在运行。 rmine 服务器的完全限定域名,使用 192.168.1.106 作为 ServerName [Mon Dec 01 11:00:22 2008] [notice] Apache/2.2.10 (Win32) 已配置 -- 恢复正常操作 [Mon Dec 01 11:00: 22 2008] [notice] 服务器构建:2008 年 10 月 10 日 12:39:04 [Mon Dec 01 11:00:22 2008] [notice] Parent:创建子进程 1844 httpd.exe:无法可靠地确定服务器的完全限定域名称,使用 192.168.1.106 作为 ServerName

标签: php apache post registration


【解决方案1】:

这个脚本不会导致 apache 死掉。在这方面没有任何问题。 但是我不知道 db_connect.php 中有什么

邮件已停用,如果服务器设置不正确,这确实可能需要很长时间。例如如果服务器无法按照您的 cmets 建议找到其完全限定的域名。

你有一个活跃的会话吗?这可以解释为什么当另一个网站仍在运行并发送邮件时您无法访问任何网站,并且在您看来它可能看起来像 apache 崩溃了。 因为您没有调用 session_write_close 并且一次只能激活一次会话以进行写入。

绝对错误的是 mysql 注入漏洞。 您绝对需要通过以下方式更改变量:

$firstname = mysql_real_escape_string($_POST['firstname']); $email = mysql_real_escape_string($_POST['email']);
$username = mysql_real_escape_string($_POST['username']);

此外,我建议您在用户名上使用唯一的 que,然后尝试插入,看看您是否收到错误或是否收到 mysq_insert_id。让 mysql 完成这项工作。 但是您的检查也很好..但是作为预防措施,您也应该在数据库中有一个约束。 并且您应该修剪您的值并且可能只允许某些字符,如果网站上的用户名是 &%DTRFG$Ä←↓ff

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-04-06
    • 2012-07-05
    • 2019-05-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多