0

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

android developer
  • 43
  • 1
  • 1
  • 11
  • Do you have `session_start()` on the first page (insertdata.php) as well? If not, you need to. You need to have it on every page that uses sessions in any way. – M. Eriksson Apr 27 '17 at 04:53
  • **Don't** use the **deprecated and insecure** `mysql_*`-functions. They have been deprecated since PHP 5.5 (in 2013) and were completely removed in PHP 7 (in 2015). Use MySQLi or PDO exclusively instead. – M. Eriksson Apr 27 '17 at 04:55
  • You are not starting the session on first page . So your session is noe setting. So please try to set the session.`session_start()` – Pranav MS Apr 27 '17 at 04:56
  • I already write session_start() in both page but not getting value @PranavMS – android developer Apr 27 '17 at 07:04

0 Answers0