简体   繁体   中英

PHP: Validate form on a page and then send data to another php page

<input id="username" name="username" class="required" type="text">

<input id="email" name="email" class="required" type="text">

I am trying to validate user input on the same page using <form action="<?php $_SERVER['SELF']; ?>" and then if the input is correct I need to send the input values + 2 additional variables to another php page, let's just call them:

<?php   
    $var1 = "var1";
    $var2 = "var2";
?>

I need a way to pass them over to the next page without using sessions/get/javascript. Is there a way?

Without sessions/get/javascript I guess your only 2 option might be

header("location:your_next_page?var1=$var1&var2=$var2");

Must be used before any output

Or

Form page:

setcookie("var1", $var1, 0, '/');
setcookie("var2", $var2, 0, '/');
//load next page

Next page:

$var1 = $_COOKIE['var1'];
$var2 = $_COOKIE['var2'];

您可以使用cookie或localStorage在浏览器上保存价值并从其他页面检索它们。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM