Lấy biến từ một tệp php khác mà không bao gồm nó

Xin chào, tôi đang làm việc với các tệp phpmailer của mình và tôi đã tạo quy tắc xác thực để kiểm tra xem các trường nhập 'nhất định' có đáp ứng yêu cầu của tôi hay không sau khi xác minh hoàn tất, họ sẽ gửi nó cho người dùng chèn địa chỉ email của họ vào cơ sở dữ liệu của chúng tôi để

Bây giờ tôi có 2 vấn đề, tệp testing.php sẽ có hàm required_once() trỏ đến tệp phpmailer của tôi với thông tin được chèn ngay bây giờ, tôi thường nhập địa chỉ email của người dùng để gửi cho họ chứ không phải tôi vì đó là đường dẫn mặc định cho thư của tôi

ví dụ cho thấy 3 trường là tất cả những gì được chỉnh sửa hoặc không được thêm vào tệp phpmailer của tôi nhưng được chèn vào testing.php tôi phải thêm hoặc xóa những gì

if (isset($_POST['FormS'])) {
require_once ('PHP/Testing.php');

echo $results;
}

if (isset($_POST['key'])) {

require_once ('PHP/sent.php');

echo $results;

}
1 để gửi thư của tôi cho người dùng để xác minh thư

require_once ($_SERVER['DOCUMENT_ROOT'] . '/test.php');

	$head = "Dear ($email)";
	$body = "Attached to this email is a generated key that is used to verify that this email account belongs to $name $srn";
	$foot = "If this is not you or you did not just try to sign up for MrLaptop.co.za email blast than feel free to ignore this email. ";
	$key  = substr(md5(uniqid(rand(), true)), 6, 6);
	
$msg = $head . "

" . $body ."

" . $key . "

" . $foot ; $mail->Subject = "From:$name $srn ($email)"; $mail->Body = $msg; $mail->AltBody = "Sent By Mrlaptop.co.za";

tên trường nhập liệu để nhập email là

if (isset($_POST['FormS'])) {
require_once ('PHP/Testing.php');

echo $results;
}

if (isset($_POST['key'])) {

require_once ('PHP/sent.php');

echo $results;

}
2 Tôi phải thêm biểu mẫu
if (isset($_POST['FormS'])) {
require_once ('PHP/Testing.php');

echo $results;
}

if (isset($_POST['key'])) {

require_once ('PHP/sent.php');

echo $results;

}
3 chỉ cần hỏi vì tôi đang cố gắng tránh những câu hỏi khó hiểu hoặc lộn xộn

Vấn đề thứ hai nằm ở dạng html vì trang ở định dạng

if (isset($_POST['FormS'])) {
require_once ('PHP/Testing.php');

echo $results;
}

if (isset($_POST['key'])) {

require_once ('PHP/sent.php');

echo $results;

}
4, vấn đề là khi email được gửi cho chính tôi trong trường hợp này, nó tạo ra một khóa ngẫu nhiên và trong biểu mẫu
if (isset($_POST['FormS'])) {
require_once ('PHP/Testing.php');

echo $results;
}

if (isset($_POST['key'])) {

require_once ('PHP/sent.php');

echo $results;

}
5 có một trường nhập được hiển thị và một trường khác

if (isset($_POST['FormS'])) {
require_once ('PHP/Testing.php');

echo $results;
}

if (isset($_POST['key'])) {

require_once ('PHP/sent.php');

echo $results;

}

tôi muốn chuyển xác thực đã được tạo trong

if (isset($_POST['FormS'])) {
require_once ('PHP/Testing.php');

echo $results;
}

if (isset($_POST['key'])) {

require_once ('PHP/sent.php');

echo $results;

}
6 và chuyển nó sang
if (isset($_POST['FormS'])) {
require_once ('PHP/Testing.php');

echo $results;
}

if (isset($_POST['key'])) {

require_once ('PHP/sent.php');

echo $results;

}
7 để tôi có thể tạo xác minh rằng khóa được tạo khớp với trường nhập vì nó sẽ được sao chép từ email của anh ấy/cô ấy, vì vậy nếu tôi tạo lại khóa đã tạo thì nó sẽ cung cấp . làm bất kỳ sự giúp đỡ sẽ được đánh giá cao xin vui lòng

Cần thêm thông tin gì chỉ cần cho tôi biết để tôi có thể thêm nó
và tôi cũng không biết mình nên áp dụng

if (isset($_POST['FormS'])) {
require_once ('PHP/Testing.php');

echo $results;
}

if (isset($_POST['key'])) {

require_once ('PHP/sent.php');

echo $results;

}
8 ở đâu và cách áp dụng nó cho khóa đã được tạo chứ không phải tập lệnh php cho nó vì nó sẽ ngẫu nhiên tạo ra một khóa mới

Lấy biến từ một tệp php khác mà không bao gồm nó
0_0Nathan

tôi muốn chuyển biến đã được tạo trong Thử nghiệm. php và di chuyển nó để gửi. php để tôi có thể tạo xác minh rằng khóa được tạo khớp với trường nhập vì nó sẽ được sao chép từ email của anh ấy/cô ấy, vì vậy nếu tôi tạo lại khóa đã tạo, nó sẽ cung cấp cho tôi một khóa được tạo khác do đó không bao giờ khớp với trường nhập. làm bất kỳ sự giúp đỡ sẽ được đánh giá cao xin vui lòng

Những người khác đã giải thích cách hoạt động của việc chuyển biến nhưng tôi muốn khuyến khích bạn thay đổi hoàn toàn cách tiếp cận của mình. Không bao gồm/các tệp bắt buộc chứa mã được thực thi trực tiếp - điều này sẽ hiệu quả nhưng theo thời gian, mã và ứng dụng của bạn sẽ trở nên lộn xộn và vô tổ chức. Bao gồm và yêu cầu không có bất kỳ cơ chế chuyển biến nào để mọi thứ trên toàn cầu được chuyển - không rõ bạn muốn chuyển cái gì vì mọi thứ đều được chuyển (một ngoại lệ là bao gồm/yêu cầu cho phép bạn

if (isset($_POST['FormS'])) {
require_once ('PHP/Testing.php');

echo $results;
}

if (isset($_POST['key'])) {

require_once ('PHP/sent.php');

echo $results;

}
9 giá trị từ chúng - nhưng chúng vẫn vậy . Tôi đã làm điều này thường xuyên khi tôi bắt đầu với PHP và kết quả thật kinh khủng khi các trang web và ứng dụng phát triển

Phương án thay thế là chỉ yêu cầu các tệp có chức năng và lớp PHP. Trong lập trình thủ tục, đây sẽ là một tập hợp các hàm và trong OOP - các lớp. Các định nghĩa hàm và lớp không được thực thi khi bạn yêu cầu chúng nên không có gì để chuyển và bạn có thể yêu cầu các tệp đó ở bất kỳ đâu trước khi thực thi các hàm hoặc lớp đó. Và hơn nữa, khi các tệp đó chứa các lớp, bạn có thể triển khai tự động tải, trong trường hợp đó, bạn không cần yêu cầu bất cứ điều gì vì nó được thực hiện tự động

Vì vậy, trong mã chính của bạn - thay vì

function Veri(){
/* Filter Remove extra spacing */
function test_input($data) {
  $data = trim($data);
  $data = stripslashes($data);
  $data = htmlspecialchars($data);
  return $data;
}

$user = test_input($_POST["name"]);
$users = test_input($_POST["surname"]);
$sender = test_input($_POST["send"]);
$msg = test_input($_POST['message']);

/* Filter empty fields and unauthorised charactures and applying variables appropriately */
if(!empty($user)){
	
	if (!preg_match("/^[a-zA-Z ]*$/",$user)) {
			$name = "User";
			$valN = 0;
			$errname = "*Your name contains elements other than text";
		}else{
			$name = test_input($_POST["name"]);
			$valN = 1;
			$errname = "";
		}
		
}else{
	$name = "User";
	$errname = "* Please Fill in Your name
"; $valN = 0; } if(!empty($users)){ if (!preg_match("/^[a-zA-Z ]*$/",$users)) { $srn = ""; $valS = 0; $errsrn = "* Your Surname contains elements other than text
"; }else{ $srn = test_input($_POST["surname"]); $valS = 1; $errsrn = ""; } }else{ $srn = ""; $valS = 1; $errsrn = ""; } if(!empty($sender)){ if (!filter_var($sender, FILTER_VALIDATE_EMAIL)) { $email = "* Please fill in a valid email address
"; $valE = 0; }else{ $email = test_input($_POST["send"]); $valE = 1; } }else{ $email = "* Please fill in a valid email address
"; $valE = 0; } if($valN + $valS + $valE >= 3){ /* Verify email address */ require_once ($_SERVER['DOCUMENT_ROOT'] . '/test.php'); $head = "Dear ($email)"; $body = "Attached to this email is a generated key that is used to verify that this email account belongs to $name $srn"; $foot = "If this is not you or you did not try to send an email to Mrlaptop.co.za using our contact Page than feel free to ignore this message "; $key = substr(md5(uniqid(rand(), true)), 6, 6); $msg = $head . "

" . $body ."

" . $key . "

" . $foot ; $mail->Subject = "From:$name $srn ($email)"; $mail->Body = $msg; $mail->AltBody = "Sent By Mrlaptop.co.za"; /* echo after verify if mail is sent */ if($mail->send()) { /* If verify was successful */ $head = "Dear $name $srn ($email)"; $body = "Please Fill in the key that was sent to $email"; $inpt = '

'; $results = $head ."
"."
". $body ."
"."
". $inpt; echo $results; }else{ /*If verify was not successful */ $head = "Dear $name $srn"; $body = "Your Email was Not successfully delivered for the following reasons:"; $inpt = "$errname
$errsrn
$email
You may have lost Internet connection"; $results = $head ."
"."
". $body ."
"."
".''. $inpt.''; echo $results; } }else{ /*If verify was not successful */ $head = "Dear $name $srn"; $body = "Your Email was Not successfully delivered for the following reasons:"; $inpt = "$errname
$errsrn
$email
"; $results = $head ."
"."
". $body ."
"."
".''. $inpt.''; echo $results; } } function mailing(){ $veri = $_POST['ans']; if($veri = $key){ /* Do some stuff */ }
0 trong ví dụ của bạn, bạn chỉ cần thực thi các hàm hoặc phương thức lớp - và chúng có sẵn các phương tiện để chuyển các biến thông qua các đối số và trả về các câu lệnh. Ví dụ: trước tiên, bạn thực thi một hàm
function Veri(){
/* Filter Remove extra spacing */
function test_input($data) {
  $data = trim($data);
  $data = stripslashes($data);
  $data = htmlspecialchars($data);
  return $data;
}

$user = test_input($_POST["name"]);
$users = test_input($_POST["surname"]);
$sender = test_input($_POST["send"]);
$msg = test_input($_POST['message']);

/* Filter empty fields and unauthorised charactures and applying variables appropriately */
if(!empty($user)){
	
	if (!preg_match("/^[a-zA-Z ]*$/",$user)) {
			$name = "User";
			$valN = 0;
			$errname = "*Your name contains elements other than text";
		}else{
			$name = test_input($_POST["name"]);
			$valN = 1;
			$errname = "";
		}
		
}else{
	$name = "User";
	$errname = "* Please Fill in Your name
"; $valN = 0; } if(!empty($users)){ if (!preg_match("/^[a-zA-Z ]*$/",$users)) { $srn = ""; $valS = 0; $errsrn = "* Your Surname contains elements other than text
"; }else{ $srn = test_input($_POST["surname"]); $valS = 1; $errsrn = ""; } }else{ $srn = ""; $valS = 1; $errsrn = ""; } if(!empty($sender)){ if (!filter_var($sender, FILTER_VALIDATE_EMAIL)) { $email = "* Please fill in a valid email address
"; $valE = 0; }else{ $email = test_input($_POST["send"]); $valE = 1; } }else{ $email = "* Please fill in a valid email address
"; $valE = 0; } if($valN + $valS + $valE >= 3){ /* Verify email address */ require_once ($_SERVER['DOCUMENT_ROOT'] . '/test.php'); $head = "Dear ($email)"; $body = "Attached to this email is a generated key that is used to verify that this email account belongs to $name $srn"; $foot = "If this is not you or you did not try to send an email to Mrlaptop.co.za using our contact Page than feel free to ignore this message "; $key = substr(md5(uniqid(rand(), true)), 6, 6); $msg = $head . "

" . $body ."

" . $key . "

" . $foot ; $mail->Subject = "From:$name $srn ($email)"; $mail->Body = $msg; $mail->AltBody = "Sent By Mrlaptop.co.za"; /* echo after verify if mail is sent */ if($mail->send()) { /* If verify was successful */ $head = "Dear $name $srn ($email)"; $body = "Please Fill in the key that was sent to $email"; $inpt = '

'; $results = $head ."
"."
". $body ."
"."
". $inpt; echo $results; }else{ /*If verify was not successful */ $head = "Dear $name $srn"; $body = "Your Email was Not successfully delivered for the following reasons:"; $inpt = "$errname
$errsrn
$email
You may have lost Internet connection"; $results = $head ."
"."
". $body ."
"."
".''. $inpt.''; echo $results; } }else{ /*If verify was not successful */ $head = "Dear $name $srn"; $body = "Your Email was Not successfully delivered for the following reasons:"; $inpt = "$errname
$errsrn
$email
"; $results = $head ."
"."
". $body ."
"."
".''. $inpt.''; echo $results; } } function mailing(){ $veri = $_POST['ans']; if($veri = $key){ /* Do some stuff */ }
1 trả về một số giá trị mà bạn gán cho một biến. Và trong bước thứ hai, bạn thực thi hàm
function Veri(){
/* Filter Remove extra spacing */
function test_input($data) {
  $data = trim($data);
  $data = stripslashes($data);
  $data = htmlspecialchars($data);
  return $data;
}

$user = test_input($_POST["name"]);
$users = test_input($_POST["surname"]);
$sender = test_input($_POST["send"]);
$msg = test_input($_POST['message']);

/* Filter empty fields and unauthorised charactures and applying variables appropriately */
if(!empty($user)){
	
	if (!preg_match("/^[a-zA-Z ]*$/",$user)) {
			$name = "User";
			$valN = 0;
			$errname = "*Your name contains elements other than text";
		}else{
			$name = test_input($_POST["name"]);
			$valN = 1;
			$errname = "";
		}
		
}else{
	$name = "User";
	$errname = "* Please Fill in Your name
"; $valN = 0; } if(!empty($users)){ if (!preg_match("/^[a-zA-Z ]*$/",$users)) { $srn = ""; $valS = 0; $errsrn = "* Your Surname contains elements other than text
"; }else{ $srn = test_input($_POST["surname"]); $valS = 1; $errsrn = ""; } }else{ $srn = ""; $valS = 1; $errsrn = ""; } if(!empty($sender)){ if (!filter_var($sender, FILTER_VALIDATE_EMAIL)) { $email = "* Please fill in a valid email address
"; $valE = 0; }else{ $email = test_input($_POST["send"]); $valE = 1; } }else{ $email = "* Please fill in a valid email address
"; $valE = 0; } if($valN + $valS + $valE >= 3){ /* Verify email address */ require_once ($_SERVER['DOCUMENT_ROOT'] . '/test.php'); $head = "Dear ($email)"; $body = "Attached to this email is a generated key that is used to verify that this email account belongs to $name $srn"; $foot = "If this is not you or you did not try to send an email to Mrlaptop.co.za using our contact Page than feel free to ignore this message "; $key = substr(md5(uniqid(rand(), true)), 6, 6); $msg = $head . "

" . $body ."

" . $key . "

" . $foot ; $mail->Subject = "From:$name $srn ($email)"; $mail->Body = $msg; $mail->AltBody = "Sent By Mrlaptop.co.za"; /* echo after verify if mail is sent */ if($mail->send()) { /* If verify was successful */ $head = "Dear $name $srn ($email)"; $body = "Please Fill in the key that was sent to $email"; $inpt = '

'; $results = $head ."
"."
". $body ."
"."
". $inpt; echo $results; }else{ /*If verify was not successful */ $head = "Dear $name $srn"; $body = "Your Email was Not successfully delivered for the following reasons:"; $inpt = "$errname
$errsrn
$email
You may have lost Internet connection"; $results = $head ."
"."
". $body ."
"."
".''. $inpt.''; echo $results; } }else{ /*If verify was not successful */ $head = "Dear $name $srn"; $body = "Your Email was Not successfully delivered for the following reasons:"; $inpt = "$errname
$errsrn
$email
"; $results = $head ."
"."
". $body ."
"."
".''. $inpt.''; echo $results; } } function mailing(){ $veri = $_POST['ans']; if($veri = $key){ /* Do some stuff */ }
2 của mình, chuyển cho nó biến đó làm đối số

function Veri(){
/* Filter Remove extra spacing */
function test_input($data) {
  $data = trim($data);
  $data = stripslashes($data);
  $data = htmlspecialchars($data);
  return $data;
}

$user = test_input($_POST["name"]);
$users = test_input($_POST["surname"]);
$sender = test_input($_POST["send"]);
$msg = test_input($_POST['message']);

/* Filter empty fields and unauthorised charactures and applying variables appropriately */
if(!empty($user)){
	
	if (!preg_match("/^[a-zA-Z ]*$/",$user)) {
			$name = "User";
			$valN = 0;
			$errname = "*Your name contains elements other than text";
		}else{
			$name = test_input($_POST["name"]);
			$valN = 1;
			$errname = "";
		}
		
}else{
	$name = "User";
	$errname = "* Please Fill in Your name
"; $valN = 0; } if(!empty($users)){ if (!preg_match("/^[a-zA-Z ]*$/",$users)) { $srn = ""; $valS = 0; $errsrn = "* Your Surname contains elements other than text
"; }else{ $srn = test_input($_POST["surname"]); $valS = 1; $errsrn = ""; } }else{ $srn = ""; $valS = 1; $errsrn = ""; } if(!empty($sender)){ if (!filter_var($sender, FILTER_VALIDATE_EMAIL)) { $email = "* Please fill in a valid email address
"; $valE = 0; }else{ $email = test_input($_POST["send"]); $valE = 1; } }else{ $email = "* Please fill in a valid email address
"; $valE = 0; } if($valN + $valS + $valE >= 3){ /* Verify email address */ require_once ($_SERVER['DOCUMENT_ROOT'] . '/test.php'); $head = "Dear ($email)"; $body = "Attached to this email is a generated key that is used to verify that this email account belongs to $name $srn"; $foot = "If this is not you or you did not try to send an email to Mrlaptop.co.za using our contact Page than feel free to ignore this message "; $key = substr(md5(uniqid(rand(), true)), 6, 6); $msg = $head . "

" . $body ."

" . $key . "

" . $foot ; $mail->Subject = "From:$name $srn ($email)"; $mail->Body = $msg; $mail->AltBody = "Sent By Mrlaptop.co.za"; /* echo after verify if mail is sent */ if($mail->send()) { /* If verify was successful */ $head = "Dear $name $srn ($email)"; $body = "Please Fill in the key that was sent to $email"; $inpt = '

'; $results = $head ."
"."
". $body ."
"."
". $inpt; echo $results; }else{ /*If verify was not successful */ $head = "Dear $name $srn"; $body = "Your Email was Not successfully delivered for the following reasons:"; $inpt = "$errname
$errsrn
$email
You may have lost Internet connection"; $results = $head ."
"."
". $body ."
"."
".''. $inpt.''; echo $results; } }else{ /*If verify was not successful */ $head = "Dear $name $srn"; $body = "Your Email was Not successfully delivered for the following reasons:"; $inpt = "$errname
$errsrn
$email
"; $results = $head ."
"."
". $body ."
"."
".''. $inpt.''; echo $results; } } function mailing(){ $veri = $_POST['ans']; if($veri = $key){ /* Do some stuff */ }
3 và
function Veri(){
/* Filter Remove extra spacing */
function test_input($data) {
  $data = trim($data);
  $data = stripslashes($data);
  $data = htmlspecialchars($data);
  return $data;
}

$user = test_input($_POST["name"]);
$users = test_input($_POST["surname"]);
$sender = test_input($_POST["send"]);
$msg = test_input($_POST['message']);

/* Filter empty fields and unauthorised charactures and applying variables appropriately */
if(!empty($user)){
	
	if (!preg_match("/^[a-zA-Z ]*$/",$user)) {
			$name = "User";
			$valN = 0;
			$errname = "*Your name contains elements other than text";
		}else{
			$name = test_input($_POST["name"]);
			$valN = 1;
			$errname = "";
		}
		
}else{
	$name = "User";
	$errname = "* Please Fill in Your name
"; $valN = 0; } if(!empty($users)){ if (!preg_match("/^[a-zA-Z ]*$/",$users)) { $srn = ""; $valS = 0; $errsrn = "* Your Surname contains elements other than text
"; }else{ $srn = test_input($_POST["surname"]); $valS = 1; $errsrn = ""; } }else{ $srn = ""; $valS = 1; $errsrn = ""; } if(!empty($sender)){ if (!filter_var($sender, FILTER_VALIDATE_EMAIL)) { $email = "* Please fill in a valid email address
"; $valE = 0; }else{ $email = test_input($_POST["send"]); $valE = 1; } }else{ $email = "* Please fill in a valid email address
"; $valE = 0; } if($valN + $valS + $valE >= 3){ /* Verify email address */ require_once ($_SERVER['DOCUMENT_ROOT'] . '/test.php'); $head = "Dear ($email)"; $body = "Attached to this email is a generated key that is used to verify that this email account belongs to $name $srn"; $foot = "If this is not you or you did not try to send an email to Mrlaptop.co.za using our contact Page than feel free to ignore this message "; $key = substr(md5(uniqid(rand(), true)), 6, 6); $msg = $head . "

" . $body ."

" . $key . "

" . $foot ; $mail->Subject = "From:$name $srn ($email)"; $mail->Body = $msg; $mail->AltBody = "Sent By Mrlaptop.co.za"; /* echo after verify if mail is sent */ if($mail->send()) { /* If verify was successful */ $head = "Dear $name $srn ($email)"; $body = "Please Fill in the key that was sent to $email"; $inpt = '

'; $results = $head ."
"."
". $body ."
"."
". $inpt; echo $results; }else{ /*If verify was not successful */ $head = "Dear $name $srn"; $body = "Your Email was Not successfully delivered for the following reasons:"; $inpt = "$errname
$errsrn
$email
You may have lost Internet connection"; $results = $head ."
"."
". $body ."
"."
".''. $inpt.''; echo $results; } }else{ /*If verify was not successful */ $head = "Dear $name $srn"; $body = "Your Email was Not successfully delivered for the following reasons:"; $inpt = "$errname
$errsrn
$email
"; $results = $head ."
"."
". $body ."
"."
".''. $inpt.''; echo $results; } } function mailing(){ $veri = $_POST['ans']; if($veri = $key){ /* Do some stuff */ }
4 của tôi không được kích hoạt ngay lập tức, chúng yêu cầu sử dụng chức năng từ chúng để chạy, nghĩa là tập lệnh của tôi chỉ chạy nếu tôi nhấp vào một số nút gửi theo cách này, nó được tổ chức khá tốt, nghĩa là tập lệnh đầu tiên xác minh đầu vào là hợp lệ và không

nếu tin nhắn được gửi thành công thì php của tôi sẽ thực thi kết quả với thông tin phù hợp, đây là một dạng khác có trường nhập yêu cầu khóa nếu nó chuyển qua một lần gửi khác, chức năng tiếp theo sẽ kích hoạt và đó là vấn đề của tôi, tôi cần sử dụng tất cả các biến của mình

Tôi chỉ có thể xác minh một lần nhưng vấn đề là mọi người sẽ bắt đầu sử dụng địa chỉ email không có thật và áp dụng vụ nổ email với địa chỉ email của người khác vì họ không được yêu cầu tự xác minh địa chỉ email. Tôi đã gặp sự cố đó. Tôi đã đăng ký vào một trang web không xác định

Ok, bản cập nhật này xứng đáng. Tôi đã thử các biến phiên và nó không hoạt động nên tôi đã thử sử dụng hàm và muốn biết

  • Sẽ tạo một lớp php cho các biến chuyển hàm giữa các hàm. (biến biểu mẫu) vì mỗi lần gửi thực thi, nó sẽ áp dụng thông tin mới cho các biến,

  • cách thêm các biến kết quả trước đó vào một hàm khác mà không ghi đè lên các biến. (khi các biến được gửi, chúng sẽ bị ghi đè bằng dữ liệu trường đầu vào nhưng không có trường đầu vào nào tồn tại cùng với tên nên chúng chuyển sang trống)

  • Làm cách nào để kích hoạt một chức năng trong một chức năng vì kết quả bị trống và tôi không biết tại sao?

Ý tưởng là các nút gửi khi gửi có tên, vì vậy trên một số lần gửi nhất định, hành động bắt đầu chức năng bằng cách sử dụng

function Veri(){
/* Filter Remove extra spacing */
function test_input($data) {
  $data = trim($data);
  $data = stripslashes($data);
  $data = htmlspecialchars($data);
  return $data;
}

$user = test_input($_POST["name"]);
$users = test_input($_POST["surname"]);
$sender = test_input($_POST["send"]);
$msg = test_input($_POST['message']);

/* Filter empty fields and unauthorised charactures and applying variables appropriately */
if(!empty($user)){
	
	if (!preg_match("/^[a-zA-Z ]*$/",$user)) {
			$name = "User";
			$valN = 0;
			$errname = "*Your name contains elements other than text";
		}else{
			$name = test_input($_POST["name"]);
			$valN = 1;
			$errname = "";
		}
		
}else{
	$name = "User";
	$errname = "* Please Fill in Your name
"; $valN = 0; } if(!empty($users)){ if (!preg_match("/^[a-zA-Z ]*$/",$users)) { $srn = ""; $valS = 0; $errsrn = "* Your Surname contains elements other than text
"; }else{ $srn = test_input($_POST["surname"]); $valS = 1; $errsrn = ""; } }else{ $srn = ""; $valS = 1; $errsrn = ""; } if(!empty($sender)){ if (!filter_var($sender, FILTER_VALIDATE_EMAIL)) { $email = "* Please fill in a valid email address
"; $valE = 0; }else{ $email = test_input($_POST["send"]); $valE = 1; } }else{ $email = "* Please fill in a valid email address
"; $valE = 0; } if($valN + $valS + $valE >= 3){ /* Verify email address */ require_once ($_SERVER['DOCUMENT_ROOT'] . '/test.php'); $head = "Dear ($email)"; $body = "Attached to this email is a generated key that is used to verify that this email account belongs to $name $srn"; $foot = "If this is not you or you did not try to send an email to Mrlaptop.co.za using our contact Page than feel free to ignore this message "; $key = substr(md5(uniqid(rand(), true)), 6, 6); $msg = $head . "

" . $body ."

" . $key . "

" . $foot ; $mail->Subject = "From:$name $srn ($email)"; $mail->Body = $msg; $mail->AltBody = "Sent By Mrlaptop.co.za"; /* echo after verify if mail is sent */ if($mail->send()) { /* If verify was successful */ $head = "Dear $name $srn ($email)"; $body = "Please Fill in the key that was sent to $email"; $inpt = '

'; $results = $head ."
"."
". $body ."
"."
". $inpt; echo $results; }else{ /*If verify was not successful */ $head = "Dear $name $srn"; $body = "Your Email was Not successfully delivered for the following reasons:"; $inpt = "$errname
$errsrn
$email
You may have lost Internet connection"; $results = $head ."
"."
". $body ."
"."
".''. $inpt.''; echo $results; } }else{ /*If verify was not successful */ $head = "Dear $name $srn"; $body = "Your Email was Not successfully delivered for the following reasons:"; $inpt = "$errname
$errsrn
$email
"; $results = $head ."
"."
". $body ."
"."
".''. $inpt.''; echo $results; } } function mailing(){ $veri = $_POST['ans']; if($veri = $key){ /* Do some stuff */ }
7 và tên chức năng

Nhưng sau khi chức năng đầu tiên được kích hoạt, nó sẽ dẫn đến một trường nhập mới yêu cầu khóa được tạo đã được gửi cho người dùng (Tôi cần tìm hiểu những gì cần chỉnh sửa để sử dụng địa chỉ email của người dùng chứ không phải địa chỉ email mặc định của tôi trong PHPmailer)

Chức năng thứ hai kích hoạt khi gửi trường nhập mới và xác minh rằng khóa được tạo giống với khóa được đính kèm trong email, vì vậy tổng cộng sẽ có 6 trường nhập không bao gồm trường nhập mới,

Ba cái đầu tiên được sử dụng trong chức năng như tên họ và email, phần còn lại được đưa đến chức năng thứ hai với phím aswel làm trường nhập liệu mới

Vấn đề tôi gặp phải là sau khi hàm đầu tiên lấy các biến và gửi email đi nhưng chúng chỉ ở dạng cục bộ nếu tôi đặt chúng ở dạng toàn cục thì hàm thứ hai sẽ ghi đè lên chúng như

function Veri(){
/* Filter Remove extra spacing */
function test_input($data) {
  $data = trim($data);
  $data = stripslashes($data);
  $data = htmlspecialchars($data);
  return $data;
}

$user = test_input($_POST["name"]);
$users = test_input($_POST["surname"]);
$sender = test_input($_POST["send"]);
$msg = test_input($_POST['message']);

/* Filter empty fields and unauthorised charactures and applying variables appropriately */
if(!empty($user)){
	
	if (!preg_match("/^[a-zA-Z ]*$/",$user)) {
			$name = "User";
			$valN = 0;
			$errname = "*Your name contains elements other than text";
		}else{
			$name = test_input($_POST["name"]);
			$valN = 1;
			$errname = "";
		}
		
}else{
	$name = "User";
	$errname = "* Please Fill in Your name
"; $valN = 0; } if(!empty($users)){ if (!preg_match("/^[a-zA-Z ]*$/",$users)) { $srn = ""; $valS = 0; $errsrn = "* Your Surname contains elements other than text
"; }else{ $srn = test_input($_POST["surname"]); $valS = 1; $errsrn = ""; } }else{ $srn = ""; $valS = 1; $errsrn = ""; } if(!empty($sender)){ if (!filter_var($sender, FILTER_VALIDATE_EMAIL)) { $email = "* Please fill in a valid email address
"; $valE = 0; }else{ $email = test_input($_POST["send"]); $valE = 1; } }else{ $email = "* Please fill in a valid email address
"; $valE = 0; } if($valN + $valS + $valE >= 3){ /* Verify email address */ require_once ($_SERVER['DOCUMENT_ROOT'] . '/test.php'); $head = "Dear ($email)"; $body = "Attached to this email is a generated key that is used to verify that this email account belongs to $name $srn"; $foot = "If this is not you or you did not try to send an email to Mrlaptop.co.za using our contact Page than feel free to ignore this message "; $key = substr(md5(uniqid(rand(), true)), 6, 6); $msg = $head . "

" . $body ."

" . $key . "

" . $foot ; $mail->Subject = "From:$name $srn ($email)"; $mail->Body = $msg; $mail->AltBody = "Sent By Mrlaptop.co.za"; /* echo after verify if mail is sent */ if($mail->send()) { /* If verify was successful */ $head = "Dear $name $srn ($email)"; $body = "Please Fill in the key that was sent to $email"; $inpt = '

'; $results = $head ."
"."
". $body ."
"."
". $inpt; echo $results; }else{ /*If verify was not successful */ $head = "Dear $name $srn"; $body = "Your Email was Not successfully delivered for the following reasons:"; $inpt = "$errname
$errsrn
$email
You may have lost Internet connection"; $results = $head ."
"."
". $body ."
"."
".''. $inpt.''; echo $results; } }else{ /*If verify was not successful */ $head = "Dear $name $srn"; $body = "Your Email was Not successfully delivered for the following reasons:"; $inpt = "$errname
$errsrn
$email
"; $results = $head ."
"."
". $body ."
"."
".''. $inpt.''; echo $results; } } function mailing(){ $veri = $_POST['ans']; if($veri = $key){ /* Do some stuff */ }
8 vì nó không tồn tại trong hàm thứ hai nên nó trả về giá trị trống

khóa được tạo sẽ tạo ra 6 số và chữ cái ngẫu nhiên nếu tôi đặt nó trên toàn cầu, chức năng thứ hai sẽ tạo ra một khóa ngẫu nhiên mới do đó không bao giờ khớp với email

Vì vậy, vâng, tôi hy vọng ai đó có thể giúp tôi về vấn đề này. Tôi đã tìm kiếm hơn một tuần nay và không thể tìm thấy câu trả lời. Làm thế nào để sử dụng nó như thế này

function Veri(){
/* Filter Remove extra spacing */
function test_input($data) {
  $data = trim($data);
  $data = stripslashes($data);
  $data = htmlspecialchars($data);
  return $data;
}

$user = test_input($_POST["name"]);
$users = test_input($_POST["surname"]);
$sender = test_input($_POST["send"]);
$msg = test_input($_POST['message']);

/* Filter empty fields and unauthorised charactures and applying variables appropriately */
if(!empty($user)){
	
	if (!preg_match("/^[a-zA-Z ]*$/",$user)) {
			$name = "User";
			$valN = 0;
			$errname = "*Your name contains elements other than text";
		}else{
			$name = test_input($_POST["name"]);
			$valN = 1;
			$errname = "";
		}
		
}else{
	$name = "User";
	$errname = "* Please Fill in Your name
"; $valN = 0; } if(!empty($users)){ if (!preg_match("/^[a-zA-Z ]*$/",$users)) { $srn = ""; $valS = 0; $errsrn = "* Your Surname contains elements other than text
"; }else{ $srn = test_input($_POST["surname"]); $valS = 1; $errsrn = ""; } }else{ $srn = ""; $valS = 1; $errsrn = ""; } if(!empty($sender)){ if (!filter_var($sender, FILTER_VALIDATE_EMAIL)) { $email = "* Please fill in a valid email address
"; $valE = 0; }else{ $email = test_input($_POST["send"]); $valE = 1; } }else{ $email = "* Please fill in a valid email address
"; $valE = 0; } if($valN + $valS + $valE >= 3){ /* Verify email address */ require_once ($_SERVER['DOCUMENT_ROOT'] . '/test.php'); $head = "Dear ($email)"; $body = "Attached to this email is a generated key that is used to verify that this email account belongs to $name $srn"; $foot = "If this is not you or you did not try to send an email to Mrlaptop.co.za using our contact Page than feel free to ignore this message "; $key = substr(md5(uniqid(rand(), true)), 6, 6); $msg = $head . "

" . $body ."

" . $key . "

" . $foot ; $mail->Subject = "From:$name $srn ($email)"; $mail->Body = $msg; $mail->AltBody = "Sent By Mrlaptop.co.za"; /* echo after verify if mail is sent */ if($mail->send()) { /* If verify was successful */ $head = "Dear $name $srn ($email)"; $body = "Please Fill in the key that was sent to $email"; $inpt = '

'; $results = $head ."
"."
". $body ."
"."
". $inpt; echo $results; }else{ /*If verify was not successful */ $head = "Dear $name $srn"; $body = "Your Email was Not successfully delivered for the following reasons:"; $inpt = "$errname
$errsrn
$email
You may have lost Internet connection"; $results = $head ."
"."
". $body ."
"."
".''. $inpt.''; echo $results; } }else{ /*If verify was not successful */ $head = "Dear $name $srn"; $body = "Your Email was Not successfully delivered for the following reasons:"; $inpt = "$errname
$errsrn
$email
"; $results = $head ."
"."
". $body ."
"."
".''. $inpt.''; echo $results; } } function mailing(){ $veri = $_POST['ans']; if($veri = $key){ /* Do some stuff */ }
9 khi chỉ có thể sử dụng ____21_______0 cục bộ trong một hàm mà nó trả về trống

Được rồi, chỉ là tôi đã thử sử dụng các phiên nhưng chúng không nhận được gì hoặc chúng bị ghi đè lên như một biến php thông thường vì cả hai đều là biểu mẫu được gửi

PHP

function Veri(){
/* Filter Remove extra spacing */
function test_input($data) {
  $data = trim($data);
  $data = stripslashes($data);
  $data = htmlspecialchars($data);
  return $data;
}

$user = test_input($_POST["name"]);
$users = test_input($_POST["surname"]);
$sender = test_input($_POST["send"]);
$msg = test_input($_POST['message']);

/* Filter empty fields and unauthorised charactures and applying variables appropriately */
if(!empty($user)){
	
	if (!preg_match("/^[a-zA-Z ]*$/",$user)) {
			$name = "User";
			$valN = 0;
			$errname = "*Your name contains elements other than text";
		}else{
			$name = test_input($_POST["name"]);
			$valN = 1;
			$errname = "";
		}
		
}else{
	$name = "User";
	$errname = "* Please Fill in Your name
"; $valN = 0; } if(!empty($users)){ if (!preg_match("/^[a-zA-Z ]*$/",$users)) { $srn = ""; $valS = 0; $errsrn = "* Your Surname contains elements other than text
"; }else{ $srn = test_input($_POST["surname"]); $valS = 1; $errsrn = ""; } }else{ $srn = ""; $valS = 1; $errsrn = ""; } if(!empty($sender)){ if (!filter_var($sender, FILTER_VALIDATE_EMAIL)) { $email = "* Please fill in a valid email address
"; $valE = 0; }else{ $email = test_input($_POST["send"]); $valE = 1; } }else{ $email = "* Please fill in a valid email address
"; $valE = 0; } if($valN + $valS + $valE >= 3){ /* Verify email address */ require_once ($_SERVER['DOCUMENT_ROOT'] . '/test.php'); $head = "Dear ($email)"; $body = "Attached to this email is a generated key that is used to verify that this email account belongs to $name $srn"; $foot = "If this is not you or you did not try to send an email to Mrlaptop.co.za using our contact Page than feel free to ignore this message "; $key = substr(md5(uniqid(rand(), true)), 6, 6); $msg = $head . "

" . $body ."

" . $key . "

" . $foot ; $mail->Subject = "From:$name $srn ($email)"; $mail->Body = $msg; $mail->AltBody = "Sent By Mrlaptop.co.za"; /* echo after verify if mail is sent */ if($mail->send()) { /* If verify was successful */ $head = "Dear $name $srn ($email)"; $body = "Please Fill in the key that was sent to $email"; $inpt = '

'; $results = $head ."
"."
". $body ."
"."
". $inpt; echo $results; }else{ /*If verify was not successful */ $head = "Dear $name $srn"; $body = "Your Email was Not successfully delivered for the following reasons:"; $inpt = "$errname
$errsrn
$email
You may have lost Internet connection"; $results = $head ."
"."
". $body ."
"."
".''. $inpt.''; echo $results; } }else{ /*If verify was not successful */ $head = "Dear $name $srn"; $body = "Your Email was Not successfully delivered for the following reasons:"; $inpt = "$errname
$errsrn
$email
"; $results = $head ."
"."
". $body ."
"."
".''. $inpt.''; echo $results; } } function mailing(){ $veri = $_POST['ans']; if($veri = $key){ /* Do some stuff */ }

biểu mẫu HTML

Contact form





Kết quả HTML/PHP

    WelcomeX

Vì vậy, biểu mẫu Html được gửi và hơn là kết quả đang sử dụng required_once() để tìm tệp cần thiết để tìm chức năng hơn là nội dung được lọc và gửi cho người dùng vào thời điểm này địa chỉ email mặc định của tôi (tôi cần thêm một

if (isset($_POST['FormS'])) {
require_once ('PHP/Testing.php');

echo $results;
}

if (isset($_POST['key'])) {

require_once ('PHP/sent.php');

echo $results;

}
1 khác cho người dùng

Hơn nữa, nó phản hồi

Contact form





3 trở lại trang html với trường nhập liệu mới

$inpt = '

'; $results = $head ."
"."
". $body ."
"."
". $inpt; echo $results;

và gửi nó cho chức năng thứ hai không nhận bất cứ thứ gì từ chức năng đầu tiên

Tôi đã thử áp dụng chức năng thứ hai bên trong chức năng đầu tiên nhưng sau khi gửi lần thứ hai, nó trả về trống thay vì lặp lại kết quả. Tôi cần một số php được nhận xét nhưng tiếng vang chỉ để xem thông tin có được thông qua hay không

Dạng thứ 2 là verify 3 trường và 1 biến còn lại

Đây là một

function mailing(){
	
	$veri = $_POST['ans'];
	
if($veri = $key){
	
	/* Do some stuff */
  1. Contact form





    4 đến từ đâu?
  2. Ý của bạn là gán giá trị của nó hoặc so sánh nó với

    Contact form





    5?

Và vâng, điều tôi thực sự muốn nói là “hãy chỉ cho chúng tôi cách bạn sử dụng các phiên và gặp sự cố với chúng”

Lấy biến từ một tệp php khác mà không bao gồm nó
0_0Nathan

và gửi nó cho chức năng thứ hai không nhận bất cứ thứ gì từ chức năng đầu tiên

Các hàm chỉ có quyền truy cập vào một trong hai giá trị mà bạn chuyển vào chúng hoặc các biến toàn cục. Do đó, hàm

Contact form





6 của bạn có thể nhìn thấy các biến

Contact form





7 vì về bản chất, chúng là các biến toàn cục. Nhưng bất kỳ giá trị cần thiết nào khác phải được khai báo toàn cầu (Điều xấu, IMO) hoặc được chuyển vào dưới dạng tham số

Tôi nghĩ lỗ hổng ở đây là bạn không lưu trữ khóa đã tạo mà người dùng của bạn phải nhập để xác nhận đăng ký của họ, vì vậy có vấn đề khi kiểm tra khóa đó khi người dùng hoàn thành biểu mẫu thứ hai. Thông thường, những gì tôi muốn thấy là, sau khi hoàn thành biểu mẫu ban đầu, thông tin chi tiết về người dùng được lưu trữ trong bảng cơ sở dữ liệu và khóa được tạo được lưu trữ cùng với chúng trong cùng một bảng hoặc một bảng khác. Sau đó, bạn dán id duy nhất của hàng người dùng vào biểu mẫu dưới dạng một biến ẩn hoặc băm email của họ hoặc một số phương tiện duy nhất để xác định người dùng. Khi họ điền vào biểu mẫu thứ hai, mã xác minh của bạn sẽ lấy mã đó, tải khóa được tạo từ nơi lưu trữ, so sánh nó với thông tin nhập của người dùng và nói có hoặc không

Lấy biến từ một tệp php khác mà không bao gồm nó
0_0Nathan

Khóa nằm ở đó chỉ được áp dụng sau khi xác minh biểu mẫu trả về true tôi muốn kiểm tra khóa đã được tạo và gửi cùng với email

Ngay sau khi hàm

Contact form





6 của bạn hiển thị biểu mẫu thứ hai, máy chủ hoàn tất việc thực thi mã PHP của bạn và tác vụ trên máy chủ, bao gồm tất cả các biến và con trỏ, không còn tồn tại nữa. Vì vậy, khi người dùng của bạn gửi biểu mẫu thứ hai, sẽ không truy xuất các biến trong bộ nhớ khi biểu mẫu được vẽ. Vì vậy, quá trình này là

server draws first form
user fills out form and hits 'submit'
server runs `testing.php` and calls veri(), checks things, all is OK so sends email and draws the second form, and exits
user waits for email with second form on screen.
user fills out second form and hits submit
server runs 'testing.php' and calls 'mailing()' which does whatever it does.

Không có tác vụ liên tục nào ngồi đó với các biến vẫn còn trong bộ nhớ, vào thời điểm người dùng nhìn thấy biểu mẫu (nói chung) thì máy chủ đã chạy xong mã PHP và đóng tác vụ

Làm cách nào để lấy biến PHP từ một tệp PHP khác?

Ba phương pháp mà bạn có thể sử dụng các biến của một tệp php trong một tệp php khác. .
sử dụng phiên để chuyển biến từ trang này sang trang khác. phương pháp. .
sử dụng phương thức get và nhận các biến khi nhấp vào liên kết. phương pháp. .
nếu bạn muốn chuyển giá trị biến bằng nút thì bạn có thể sử dụng nó theo phương pháp sau. $x='giá trị1'

Làm cách nào để chuyển biến từ trang PHP này sang trang PHP khác mà không có biểu mẫu?

php // page1. php session_start(); echo 'Welcome to page #1'; $_SESSION['favcolor'] = 'green'; $_SESSION['animal'] = 'cat'; $_SESSION['time'] = time(); // Works if session cookie was accepted echo '
page 2'; // Or pass along the session id, if needed echo '
Làm cách nào để truy cập biến toàn cục trong PHP từ một tệp khác?
$GLOBALS là một biến siêu toàn cầu PHP được sử dụng để truy cập các biến toàn cục từ bất kỳ đâu trong tập lệnh PHP (cũng như từ bên trong các hàm hoặc phương thức). PHP lưu trữ tất cả các biến toàn cục trong một mảng có tên là $GLOBALS[index]. Chỉ mục giữ tên của biến

Làm cách nào để lấy dữ liệu từ trang này sang trang khác trong PHP?

Chuyển dữ liệu từ trang này sang trang khác trong PHP . Sử dụng $_POST['field_name'] chúng tôi nhận dữ liệu biểu mẫu trên một trang khác trong PHP nếu phương thức được đăng trong trường hợp sử dụng phương thức get $_GET['field_name'];.