Python - PHPSESSID

Asked

Viewed 203 times

2

Well I’m trying to create a script who enters a website without having to log in through the library requests. I want to do it using the PHPSESSID.

How can I do this?

  • Why without the requests library?

  • in vdd I need it, the problem is I don’t want to send login/password. I just want to send PHPSESSID instead of having to log in understand? It is q the site I want to enter has captcha there is no way to send the Formularios, then the way would be log in through the browser, pick up the cookies and do a kind q a 'hijack'.

  • I understand, but how do you want to grab a valid PHPSESSID without logging in first? This will need to be checked on the server side and the server will see if PHPSESSID equals what it has saved for that session. And this is only set when logging in... No PHPSESSID login in this context does not exist. You can do all this with requests... If I may say, what is the site? see if I can help you

  • of course, but I will login through the browser, then I get the browser ID and play in my script.

  • Ha ok... I see. You will have to send all cookies... Most likely you will not only have this saved

  • the website and br.hackerexperience.com

  • br.hackerexperience.com

  • You know the code needed to send a cookie through requests?

  • I put down the way to do this, along with the documentation link

Show 4 more comments

1 answer

1


To send cookies together with request, using the lib requests:

import requests

s = requests.Session()

r = s.get('http://httpbin.org/cookies', cookies={'CHAVE1': 'VALOR1', 'CHAVE2': 'VALOR2'})
print(r.status_code)
print(r.text)

Remember that there is probably not only one verification cookie, you have to send them all. This example in principle works both in python2 and 3.

Can set headers also and send together:

...
headers = {'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:47.0) Gecko/20100101 Firefox/47.0'}
r = s.get('http://httpbin.org/cookies', headers=headers, cookies={'CHAVE1': 'VALOR1', 'CHAVE2': 'VALOR2'})
  • OK thank you! I’ll test

  • Thank you very much I managed sending only the PHPSESSID thank you very much I was researching there are two days.

  • ready friend clicked !

Browser other questions tagged

You are not signed in. Login or sign up in order to post.