PHP : Unable to assign posted data (coming from python) to session

Viewed 102

I am sending signature of pc from python to php and in php i want to use signature on next pages so that's why i am storing it in session variable but i am unable to set session variable don't know why? below is my code any help would be appreciated. Here is my python script.

url = 'http://localhost:9090/project/php/signature.php'

username = getpass.getuser ( )

mac_address = uuid.getnode ( )

#process_id = os.getpid ( )

device_name = socket.gethostname ( )

signature = username + str ( mac_address ) +  device_name
print(signature)

post = { 'sign' : signature }
req = urlencode ( post ).encode ( "utf-8" )
req = requests.post(url, post)
#req.add_header ( "Content-type" , "application/x-www-form-urlencoded" )
print(req.text)

Here is my php script.

<?php
session_start();
if(isset($_POST['sign']))
{
    $sign = $_POST['sign'];
    $_SESSION["sig"] = $_POST['sign'];
    if(!is_dir($sign))
    {
        mkdir($sign);
        echo "folder created";
    }
    else
    {
        echo "folder already exists";
    }
}
else
{
    echo "nothing found";
}

var_dump($_SESSION);
?>

when i run php script it successfully creates folder using signature coming from python but output of var_dump($_SESSION) C:\wamp64\www\project\php\signature.php:22: array (size=0) empty if anyone has any solution of this kindly help. Thank you.

0 Answers
Related