开发者

registration via php

I've been reading alot of tutorials on how to and looking at samples regarding registration. I have my database config file, reg_form and register-exec files. When I try on a production server, I get file not found for register-exec.

Here's my 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>

The following is the register-exec.php file, I'm not sure where I went wrong with it.

<?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["f开发者_如何学Goname"] . " is now the proud owner of a VMATSIM account.";
        $sql = "UPDATE users SET act_key = ''";


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

}
?>

Any pointers would be very helpful.


Make sure your reg_form.php, db_conn.php and register-exec.php are in the same location or make sure to specify the path to them when calling/using them.


Try to test, if you can call the files manually to see if it is a permission issue. Simply type into your browser the full path to the file.

Depending on how you copied it, you might not enjoy the same permissions on your production server and thus PHP can't access the file. Try setting it with

chmod 777 filename.php 

and then if it works, make sure you revert back to the amount of privileges you need.

If the files are sitting in a different locations give the absolute path:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜