1

In my android application i call php web service .at the first service is checking the login page if the user and the password are correct ,i create a new session for this user and i call this variable in another php page to treat some request .. The problem is when i call this variable from my android app it tells me:Undefined index :id_utilisateur in c:/wamp..../ajouteroffre.php

My login page is:

  session_start();
  include("mesfonction.php");
  require "init.php";

   $user_name =@$_POST["login_name"]; 
   $user_pass =@$_POST["login_pass"]; 


  $rows  = checkloginConnexion($user_name, $user_pass);
   $count = count($rows);

    if( $count==1 )
    {
    $_SESSION['id_utilisateur']=$rows[0]['ID_User'];
    $_SESSION['profile']=$rows[0]['Profil'];

    $_SESSION['login']=$user_name;
    $_SESSION['pass']=$user_pass;  

    if ($_SESSION['profile'] =='Employeur') 
       {


       echo "Connecte en tant que Employeur..";

        }       

     if ($_SESSION['profile'] =='Chercheur') 
       {
        echo "Connecte en tant que Candidat..";
        }           


      }
     else 
      {
     echo "Erreur:Connexion...Reesseyez!";
     }

    ?>

My second page is:

<?php  
 session_start();
 require "init.php";  
 include("mesfonction.php");


 $id_user =$_SESSION["id_utilisateur"];
 $ThisUser = getInfopro($id_user);

?>

Thank you for help

2
  • which one is the file ajouteroffre.php? Commented Apr 27, 2016 at 8:53
  • The second one which call the login page Commented Apr 27, 2016 at 9:23

2 Answers 2

1

try below code :-

session_start();
include("mesfonction.php");
require "init.php";
 **Change**
session_start();
ob_start();
include("mesfonction.php");
require "init.php";
Sign up to request clarification or add additional context in comments.

2 Comments

the problem is the same! when i tried the web service at localhost it gives me the right response but when running my android app it displays an empty message without any error!
include("../mesfonction.php");
0

i think your android application didn't request with cookie like sessionID, so the web server can not find the session.

Differences between cookies and sessions:

Sessions are server-side files that contain user information, while Cookies are client-side files that contain user information. Sessions have a unique identifier that maps them to specific users. This identifier can be passed in the URL or saved into a session cookie.

Most modern sites use the second approach, saving the identifier in a Cookie instead of passing it in a URL (which poses a security risk). You are probably using this approach without knowing it, and by deleting the cookies you effectively erase their matching sessions as you remove the unique session identifier contained in the cookies.

you can use OAuth2.0 to solve the problem http://oauth.net/2/

Process is as follows:

  • step1:input username and password in android app
  • step2:android app send the info to web service
  • step3:after web service authenticating,return a token to app
  • step4:get other resource with the token

7 Comments

Thank you for thelp but when i tried the web service at localhost it gives me the right response but when running my android app it displays an empty message without any error!
“i tried the web service at localhost it gives me the right response” You are using a browser?
yes i test it at the browser it gives me the value 2 which is stored in $_SESSION['id_utilisateur']; ... But when i call it from android it return an empty message without any error
i think ,the browser will automatically maintain a cookie but not android.so the web server didn't who you are when you call it from android
aah clear! do you have please any idea about this and how can i solve this problem!
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.