通过PHP注册

时间:2011-08-15 12:44:33

标签: php mysql registration

我一直在阅读很多有关如何注册和查看注册样本的教程。我有我的数据库配置文件,reg_form和register-exec文件。当我尝试生产服务器时,我找不到register-exec的文件。

这是我的reg_form:

<?php

session_start ();


?>
<html>
<head>
<title>Login Form</title>
</head>
<body>
<?php
if( isset($_SESSION['ERRMSG_ARR']) && is_array($_SESSION['ERRMSG_ARR']) && count       ($_SESSION['ERRMSG_ARR']) >0 ){
echo '<ul class="err">';
foreach($_SESSION['ERRMSG_ARR'] as $msg) {
    echo '<li>',$msg,'</li>';
    }
    echo '</ul>';
    unset($_SESSION['ERRMSG_ARR']);
 }
?>
</body>
<form id="loginForm" name="loginForm" method="post" action="register-exec.php">
<table width="300" border="0" align="center" cellpadding="2" cellspacing="0">
<tr>
<th>Full Name</th>
<td><input name="fname" type="text" class="textfield" id="fname" /></td> 
</tr>
<tr>
<th>Email Address (Must be valid)</th>
<td><input name="email" type="text" class="email" id="email" /></td>
</tr>
<tr>
<th>Password (must not be longer than 6)</th>
<td><input name="password" type="password" class="textfield" id="password" /></td>
</tr>
<tr>
<th>Confirm Password</th>
<td><input name="copassword" type="password" class="textfield" id="copassword" />"</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="hidden" name="form_submitted" value="1" />"<input type="submit" name="submit" value="Register" />"</td>
</tr>

</table>

以下是register-exec.php文件,我不确定它在哪里出错。

<?php
//Start session
session_start();

//Include database
require_once('db_conn.php');

//Array to store validation errors
$errmsg_arr = array();

//Validation error flag
$errflag = false; 

//Create a random 6 digit cid for users
$new_cid = mt_rand(100000, 999999);

//Create random activation key
$act_key = mt_rand().mt_rand().mt_rand().mt_rand().mt_rand();

//Connect to mysql
$link = mysql_connect (DB_HOST, DB_USER, DB_PASSWORD);
if (!$link){
die('Failed to connect to server: ' . mysql_error());
  }

//Select database
$db = mysql_select_db(DB_DATABASE);
if(!$db) {
die("Unable to select database");
}

//Sanitize the values
$fname = clean($_POST['fname']);
$email = clean($_POST['email']);
$password = clean($_POST['password']);
$copassword = clean($_POST['copassword']);

//Make sure they submitted the form
if($_POST['form_submitted'] == '1'){    


//Make sure they inputted information
if($fname == '') {
$errmsg_arr[] = 'Full Name missing';
$errflag = true;
 }
if($email == ''){
$errmsg_arr[] = 'Email missing';
$errflag = true;
 }
if($password == ''){
$errmsg_arr[] = 'Missing password';
$errflag = true;
}
if($copassword == ''){
$errmsg_arr[] = 'Confirm password missing';
$errflag = true;
}
if( strcmp($password, $copassword) != 0 ){
$errmsg_arr[] = 'Passwords do not match';
$errflag = true; 
} 
$sql="INSERT INTO users (fname, email, password, act_key, cid) VALUES ('$fname',  '$password', '$act_key', '$new_cid')";
if (!mysql_query($sql))
{
die('Error:' . mysql_error());

} 

 echo "An email has been sent to $_POST[email] with an activation key. Please check your mail to complete registration.";

//Send the first activation email
$to          = $_POST['email'];
$subject = "VMATSIM Registration";
$message = "Welcome to VMATSIM. You or someone using your email address has completed registration at vmatsim.net. You can complete reigstration by clicking the following link:\rhttp://vmatsim.net/register-exec.php?$act_key\r\rIf this is an error, ignore this email and you will be removed from our system.\r\rRegards, VMATSIM Team";
$headers = 'From: noreply@vmatsim.net' . "\r\n" .

'Reply-To: noreply@vmatsim.net' . "\r\n" .

'X-Mailer: PHP/' . phpversion();

mail($to, $subject,$message,$headers);


//User is activating
} else {

$queryString = $_SERVER['QUERY_STRING'];
$query = "SELECT * FROM users";
$result = mysql_query($query) or die (mysql_error());
while($row = mysql_fetch_array($result)){
    if($queryString == $row["act_key"]){
        echo "Congratulations" . $row["fname"] . " is now the proud owner of a VMATSIM account.";
        $sql = "UPDATE users SET act_key = ''";


        if(!mysql_query($sql))
        {
            die('Error:' . mysql_error());
        }
    }
}

}
?>

任何指针都会非常有用。

2 个答案:

答案 0 :(得分:0)

确保 reg_form.php db_conn.php register-exec.php 位于同一位置或确保指定调用/使用它们时的路径。

答案 1 :(得分:0)

尝试测试,如果您可以手动调用文件以查看它是否是权限问题。只需在浏览器中输入文件的完整路径即可。

根据您的复制方式,您可能无法在生产服务器上享有相同的权限,因此PHP无法访问该文件。尝试使用

进行设置
chmod 777 filename.php 

然后如果有效,请确保恢复到所需的权限数量。

如果文件位于不同的位置,则给出绝对路径:

require_once("/var/config/my_config_files.php");