2

I have two android separate apps sending data to php(xampp) server. I am sending data from app1 to test1.php and from app2 to test2.php. After that I would like to access the data from test1.php using session and do some stuff in app2.php. I am successful in sending the data from my android apps. But I am not getting the data in test2.php. This is test1.php.

<?php 
        //session 
        session_start();

        $json = file_get_contents("php://input");
        $jsondecoded = json_decode($json, TRUE);
        $Id = $jsondecoded['ID'];  

        $_SESSION['id'] = $Id;
?>

Here is test2.php

<?php 
        //session
        session_start(); 

        $myid=$_SESSION['id'];
?>
0

1 Answer 1

2

Your problem is that app1 and app2 will start different sessions. You will never be able to have the same session in both apps if you don't share the session_id between them.

Sign up to request clarification or add additional context in comments.

5 Comments

test1.php and test2.php are two different pages of the same project in the server. Now my question is how do I access the variable in the former. Isn't session global within the whole project?
Even if both php files belong to the same project, and are stored in the same server, app1 and app2 act like different hosts, so each app will create a new different session with a unique session id. You will need to create a mechanism that shares the session id from one app to the other app when the first app creates the session.
I tried to POST the values but no luck. Can you give me an example?All the SO questions are server-browser scenarios. I appreciate your help.
No matter if you use POST or GET, the session id will be unique for each app, What you have to do is that when one app creates the session, the second app should recieve somehow that session id in order to send it to the PHP and retreive the same session that the first app created.
Another thing to do is generete the session id yourself, and both apps should have that session id and send it to the PHP, but generating your own session id's can lead to phishing. I recommend you ask another question here in SO with a title like "How can I share a PHP session between two different Android Applications".

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.