In my android app, I want unique id for every user. I have already done with $uuid = uniqid('', true); this fuction in php. It will generate unique id per user and it will store in database. Now I want to get this id on next page. I will use 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;
}
}
Using this code it will successfully stored in database. now get this value from session on another page.In this code I don't get session value in browser but I will get in postman.
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