-3

我只想知道如何将输入值(例如电子邮件)转换为会话

4

5 回答 5

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']);
于 2013-03-04T05:07:27.653 回答
4
session_start();

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

或者

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

或者

$_SESSION['email'] = $_REQUEST['email'];
于 2013-03-04T05:06:26.530 回答
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'];
于 2013-03-04T05:15:20.667 回答
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']
于 2013-03-04T05:15:02.347 回答
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'];
}
于 2013-03-04T06:15:48.530 回答