I am writing a python script to submit a post request with data. I got the below programme which works fine for login. and i get value "cloud" for a.text. but i am not able to submit next post request to the server because the in php application i have isset($_SESSION['user_name']. if user_name is not set then it will redirect to homepage. the below code redirects to home page. I want to set the a.text to $_SESSION[user_name]. how to do it
import requests
loginurl = 'http:localhost/login.php'
loginparams = {'username': 'admin', 'password' : '1234'}
targeturl = 'http:localhost/add.php'
params={'firstname':'cloud', 'lastname':'kicker'}
def main():
login = requests.Session()
a = login.post(loginurl, loginparams)
print a.text # i get username for this line
login.post(targeturl, params, cookies={'user_name': a.text})
return 0
if __name__ == '__main__':
main()