0

I have create login for android and iphone app in cocos2dx..

After login, in the next page i get data successfully in ios simulator but in android phone it is getting null.

Here json reply log in android -

res: {"F":null,"W":null,"T":null,"Fp":null,"Wp":null,"Tp":null,"msg":"Invalid","sid":null}

And in Ios Simulator -

res: {"F":"135","W":"1","T":"1","Fp":"1","Wp":"1","Tp":"1","msg":"success","sid":"1nf9ecj3j2nmm2lmamblf27n34"}

the same server code is returning success in ios simulator and invalid via android..

in login.php i set session id (sid)-

      $postdata = file_get_contents("php://input");
parse_str($postdata, $get_array);

 //print_r($get_array);


 $id = $get_array['id']; 
 $pass = $get_array['pass']; 


$link = mysqli_connect("localhost", "aaa", "aaa", "aa");

// Check connection
if($link === false){
    die("ERROR: Could not connect. " . mysqli_connect_error());

    echo ("connection failed");
}

// Attempt select query execution
$sql = "SELECT `uid` FROM userdetails WHERE uname = '$id' AND pass = '$pass'";
//$query = mysql_query($sql);

$msg;

if($query = mysqli_query($link, $sql)){
if (mysqli_num_rows($query) >= 1)
{
     while($row = mysqli_fetch_assoc($query)) {

        $value = $row['uid'];

     }


    session_start();
    $a = session_id();

    $_SESSION['sid'] = $a;
    $_SESSION['userid'] = $value;
    $_SESSION['name'] = $id;


    $msg = "success";
        }

    else{


        $msg = "fail";

    }
  }

  else
{
    $msg = "dberror";
}



header('Content-type: application/json');
$data2 = array('sid' => $a ,'msg' => $msg);
echo json_encode($data2);

// Close connection
//mysqli_close($link);


?>

2nd page - getstats.php - i sent session id generated in login via POST to getstats.php as sid

 <?php

//gettrees

session_start();




$postdata = file_get_contents("php://input");
parse_str($postdata, $get_array);

 //print_r($get_array);

 $msg;
 $sesid = $get_array['sid']; 
$serverid = $_SESSION['sid'];


if($_SESSION['sid'] == $sesid)

 {

$link = mysqli_connect("localhost", "aaa", "aaa", "aa");


// Check connection
if($link === false){
    die("ERROR: Could not connect. " . mysqli_connect_error());
}

  $userid =  $_SESSION['userid'];

//  echo "uuuuuuuuuuuuuuuuuuuu";
//  echo $userid;


// Attempt select query execution
$sql = "SELECT `F`,`W`,`T`,`Fp`,`Wp`,`Tp` FROM groupdetails WHERE uid='$userid'";
//$query = mysql_query($sql);


if($query = mysqli_query($link, $sql)){
if (mysqli_num_rows($query) > 0)  
{  
    while($row = mysqli_fetch_assoc($query)) {


     $F = $row['F'];
     $W = $row['W'];
     $T = $row['T'];
     $Fp = $row['Fp'];
     $Wp = $row['Wp'];
     $Tp = $row['Tp'];
    }
    $msg = "success";

}
    else
    {
        $msg = "No Records";
    }
} 

else
{
    $msg = "db error";
}


}
  else
  {
      $msg = "Invalid";

  }



 $dir = "../imgs/";
 $list = array();

// Open a directory, and read its contents
if (is_dir($dir)){
  if ($dh = opendir($dir)){
    while (($file = readdir($dh)) !== false){
        if ($file == "." or $file == "..") continue;
        $list[] = $file;
     // echo $file;
    }
    closedir($dh);
  }
}

 header('Content-type: application/json');
 $data2 = array( 'F' => $userid, 'W' => $W, 'T' => $T, 'Fp' => $Fp, 'Wp' => $Wp, 'Tp' => $Tp, 'list' => $list, 'msg' => $msg , 'sid' => $serverid );
 echo json_encode($data2);

// Close connection
mysqli_close($link);


?>

$_SESSION['sid'] or $serverid return null in android phone but right value from ios simulator.

Any help will be appreciated. Thank you

user2897282
  • 81
  • 1
  • 5
  • 14
  • Your code is vulnerable to [**SQL injection**](https://en.wikipedia.org/wiki/SQL_injection) attacks. You should use prepared statements with bound parameters, via either the [**mysqli**](https://secure.php.net/manual/en/mysqli.prepare.php) or [**PDO**](https://secure.php.net/manual/en/pdo.prep ared-statements.php) drivers. [**This post**](https://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) has some good examp les. – Alex Howansky Aug 31 '17 at 15:44
  • Thanks @AlexHowansky before launching will take care of sqlinjection, but right now stuck with this issue.. – user2897282 Aug 31 '17 at 16:07

0 Answers0