如何将输入值转换为会话变量?

时间:2013-03-04 05:04:35

标签: php

我只是想知道如何将输入值转换成电子邮件发送到会话

5 个答案:

答案 0 :(得分:4)

session_start();

$_SESSION['email'] = $_POST['email'];

$_SESSION['email'] = $_GET['email'];

$_SESSION['email'] = $_REQUEST['email'];

答案 1 :(得分:4)

session_start(); // at the beginning of your code.
$_SESSION['email'] = $email; // if the variable already initiated.




$_SESSION['email'] = $_POST['email']; // coming from HTML FORM with method = POST
$_SESSION['email'] = $_GET['email']; // coming from HTML FORM with method = GET

然后,转到另一个php文件并执行此操作

session_start();
$email = $_SESSION['email'];

如果您需要随时销毁会话。你需要取消设置会话

unset($_SESSION['email']);

答案 2 :(得分:2)

看起来你需要自己一本好的PHP书,并阅读了很多。

只是为了让你朝着正确的方向前进,首先,输入将在$ _GET或$ _POST超全局中提供,请参阅:

其次,确保您需要写入会话或从会话中读取的每个页面都有一个session_start()调用:http://php.net/manual/en/function.session-start.php

最后,会话变量可以通过$ _SESSION超全局:http://www.php.net/manual/en/reserved.variables.session.php获得。

所以在这一点上,您可以将输入写入会话,如下所示:

session_start();
$_SESSION['email'] = $_GET['email']; // assuming your email came in a GET request

在另一个页面中,您可以像这样阅读会话变量:

session_start();
$local_variable_email = $_SESSION['email'];

答案 3 :(得分:0)

您的输入类型:

<input type="text" name="email" />

然后

session_start();
$_SESSION['email'] = $emailvariable;  
$emailvariable = $_POST['email'];

  //email is the name you assigned in your input type. 
  //emailvariable is any variable you want to assign.   

并在您的不同页面中

session_start();
$emailvariable = $_SESSION['email']

答案 4 :(得分:0)

  session_start();  
if(isset($_POST['email']){
  $_SESSION['email'] = $_POST['email'];
}

OR
if(isset($_GET['email']){
  $_SESSION['email'] = $_GET['email'];
}
OR

if(isset($_REQUEST['email']){
  $_SESSION['email'] = $_REQUEST['email'];
}