PHP和Javascript-未定义变量的问题
嘿,伙计们,我对这个很陌生,所以我很抱歉,如果我在这里遗漏了一些完全愚蠢的东西。我有下面的报名表。在URL中,我试图提交值e。但是,在所有情况下,e都是空的或未定义的:PHP和Javascript-未定义变量的问题,javascript,php,Javascript,Php,嘿,伙计们,我对这个很陌生,所以我很抱歉,如果我在这里遗漏了一些完全愚蠢的东西。我有下面的报名表。在URL中,我试图提交值e。但是,在所有情况下,e都是空的或未定义的: <?php // Ajax calls this REGISTRATION code to execute if(isset($_POST["u"])){ // CONNECT TO THE DATABASE include_once("php_includes/db_conx.php");
<?php
// Ajax calls this REGISTRATION code to execute
if(isset($_POST["u"])){
// CONNECT TO THE DATABASE
include_once("php_includes/db_conx.php");
// GATHER THE POSTED DATA INTO LOCAL VARIABLES
$u = preg_replace('#[^a-z0-9]#i', '', $_POST['u']);
$p = $_POST['p'];
$e = $_GET['e'];
echo "test";
echo "$e";
// GET USER IP ADDRESS
$ip = preg_replace('#[^0-9.]#', '', getenv('REMOTE_ADDR'));
// DUPLICATE DATA CHECKS FOR USERNAME AND EMAIL
$sql = "SELECT id FROM team WHERE username='$u' LIMIT 1";
$query = mysqli_query($db_conx, $sql);
$u_check = mysqli_num_rows($query);
// FORM DATA ERROR HANDLING
if($u == "" || $p == ""){
echo "The form submission is missing values.";
exit();
} else if ($u_check > 0){
echo "The username you entered is alreay taken";
exit();
} else if (strlen($u) < 3 || strlen($u) > 16) {
echo "Username must be between 3 and 16 characters";
exit();
} else if (is_numeric($u[0])) {
echo 'Username cannot begin with a number';
exit();
} else {
// END FORM DATA ERROR HANDLING
// Begin Insertion of data into the database
// Hash the password and apply your own mysterious unique salt
$cryptpass = crypt($p);
include_once ("php_includes/randStrGen.php");
$p_hash = randStrGen(20)."$cryptpass".randStrGen(20);
// Add user info into the database table for the main site table
$sql = "UPDATE team
SET username='$u',password='$p_hash',ip='$ip',signup=now(),lastlogin=now(),notecheck=now()
WHERE email='$e'";
$query = mysqli_query($db_conx, $sql);
$uid = mysqli_insert_id($db_conx);
// Create directory(folder) to hold each user's files(pics, MP3s, etc.)
if (!file_exists("user/$u")) {
mkdir("user/$u", 0755);
}
// Email the user their activation link
$to = "$e";
$from = "auto_responder@yoursitename.com";
$subject = 'Account Activation';
$message = '<!DOCTYPE html><html><head><meta charset="UTF-8">
<title>yoursitename Message</title></head>
<body style="margin:0px; font-family:Tahoma, Geneva, sans-serif;">
<div style="padding:10px; background:#333; font-size:24px; color:#CCC;">
<a href="http://www.yoursitename.com"><img src="http://www.rockaholics-cologne.de/root/images/logo.png" width="36" height="30" alt="yoursitename" style="border:none; float:left;"></a>Account Activation</div>
<div style="padding:24px; font-size:17px;">Hello '.$u.',<br /><br />Click the link below to activate your account when ready:<br /><br /><a href="http://www.rockaholics-cologne.de/root/activation.php?id='.$uid.'&u='.$u.'&p='.$p_hash.'">Click here to activate your account now</a><br /><br />Login after successful activation using your:<br />* Username: <b>'.$u.'</b></div></body></html>';
$headers = "From: $from\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\n";
mail($to, $subject, $message, $headers);
echo "signup_success";
exit();
}
exit();
}
?>
我认为$\u GET['e']在原始脚本中不起作用,因为它没有从表单页面传递到处理脚本。我访问了您提供的URL()。请注意,在提交表单时,URL中的“e”值不会传递给正在处理脚本的任何人。在表单中,您需要执行以下操作之一:
<input type="hidden" name="e" value="<?php echo $_GET['e']?>" />
验证/清理$\u POST['u']
输入值的方法是getenv('REMOTE\u ADDR')
非常有趣。使用正则表达式模式测试得到的修剪值,而不是删除所有不需要的字符。在发布之前,您应该执行urlencode($e),在mailDeclare“e”中发布“@”符号不可以作为变量var e=((“e”).value
您使用的是“e”“+e+”
,您没有将“e”声明为变量。非常推荐阅读:非常感谢您的回答,我一定会在程序运行后让程序更加安全。但到目前为止,我仍然不明白为什么它在我的测试代码中回显$e,但在我的大型php函数中却无法识别$e!?谢谢我昨天终于放弃了,尝试了一些类似于隐藏输入的东西:)谢谢大家
function signup(){
var u = _("username").value;
var p1 = _("pass1").value;
var p2 = _("pass2").value;
var status = _("status");
if(u == "" || p1 == "" || p2 == ""){
status.innerHTML = "Fill out all of the form data";
} else if(p1 != p2){
status.innerHTML = "Your password fields do not match";
} else {
_("signupbtn").style.display = "none";
status.innerHTML = 'please wait ...';
var ajax = ajaxObj("POST", "signup.php");
ajax.onreadystatechange = function() {
if(ajaxReturn(ajax) == true) {
if(ajax.responseText.replace(/^\s+|\s+$/g, "") == "signup_success"){
status.innerHTML = ajax.responseText;
_("signupbtn").style.display = "block";
} else {
window.scrollTo(0,0);
_("signupform").innerHTML = "OK "+u+", check your email inbox and junk mail box at <u>"+e+"</u> in a moment to complete the sign up process by activating your account. You will not be able to do anything on the site until you successfully activate your account.";
}
}
}
ajax.send("u="+u+"&p="+p1);
}
}
<form action="{yourscripturl}?e=<?php echo $_GET['e']?>" {rest of form tag}>
<input type="hidden" name="e" value="<?php echo $_GET['e']?>" />