在我的Android应用中,我希望每个用户都有唯一的ID。我已经完成了$ uuid = uniqid('',true);这个功能在PHP中。它将为每个用户生成唯一的ID,它将存储在数据库中。现在我想在下一页上获得此ID。我会用session。
Inserdata.php
public function StoreSocialInfo($firstname, $lastname, $email)
{
$uuid = uniqid('', true);
$_SESSION["newsession"] = $uuid;
$stmt = $this->conn->prepare("INSERT INTO ibeInsert(unique_id,firstname,lastname,email) VALUES(?,?,?,?)");
$stmt->bind_param("ssss", $uuid,$firstname,$lastname,$email);
$result = $stmt->execute();
$stmt->close();
if($result)
{
$stmt = $this->conn->prepare("SELECT firstname,lastname,email,unique_id FROM ibeInsert WHERE email = ?");
$stmt->bind_param("s",$email);
$stmt->execute();
$stmt->bind_result($token2,$token3,$token4,$token5);
while( $stmt->fetch() )
{
$user["firstname"]=$token2;
$user["lastname"]=$token3;
$user["email"]=$token4;
$user["unique_id"]=$token5;
}
$stmt->close();
return $user;
}
else
{
return false;
}
}
使用此代码,它将成功存储在数据库中。现在从另一个页面上的会话中获取此值。在此代码中,我没有在浏览器中获取会话值,但我将进入邮递员。
getdata.php
<?php
session_start();
error_reporting(E_ALL);
ini_set('display_errors', 1);
$dbhost = 'localhost';
$dbuser = '***';
$dbpass = '***';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
$uuid = $_SESSION['newsession'];
var_dump($uuid);
$sql = "SELECT * FROM ibeInsert where unique_id = $uuid ";
mysql_select_db('****');
$retval = mysql_query( $sql, $conn );
$response = array();
if(! $retval )
{
die('Could not get data: ' . mysql_error());
}
while($row = mysql_fetch_assoc($retval))
{
array_push($response,array("status"=>$row["status"],
"unique_id"=>$row["unique_id"],"elite_id"=>$row["elite_id"]));
}
echo json_encode($response);
mysql_close($conn);
?>
here I will get session value on another page in postman here I will get null response in web browser