0

I created a very simple login system.It works well when I manually login.Now, I am writing a python program to login to my system using POST request but it's not working.

Below is the python code that I'm working on.When I run this program,it somehow can't get authenticated and shows the source page content of the login page itself.My expectation is to see the source page content of the logged-in user (in this case,admin).

import requests 
url = "http://127.0.0.1/userregistration/login.php"
info = {'user': 'admin', 'password': 'password', 'Submit': 'submit'}
response = requests.post(url, data=info)
print(response.text)

this is the source code for my login system.

<html>
<form action='validation.php' method='post'>
<fieldset>
    <legend>Login</legend>
    <label>UserName</label>
    <input type='text' name='user'>
    <label>Password</label>
    <input type='password' name='password'>
    <input type='submit' name='Submit' value='Login' >
</fieldset>
</form>
</html>

Can you please give me some advice ? Thanks!!

Draco
  • 1
  • 1
  • One might need to look at `login.php`. But perhaps you need simply to make the following change: `info = {'user': 'admin', 'password': 'password', 'Submit': 'Login'}` to bring it more in line with the actual form (i.e. 'submit` -> 'Login'). – Booboo Apr 24 '20 at 12:49

2 Answers2

0

the login page is your referer and the validation page is where you send your post request .

Try this approach :

import requests 
url = "http://127.0.0.1/validation.php"
headers = {'referer': 'http://127.0.0.1/userregistration/login.php'}
info = {'user': 'admin', 'password': 'password', 'Submit': 'submit'}
response = requests.post(url, data=info,headers = headers )
print(response.text)

another idea is that you are not sending the right post parameters for the submit which value is Login and you are passing it wrong

import requests 
url = "http://127.0.0.1/userregistration/login.php"
info = {'user': 'admin', 'password': 'password', 'Submit': 'Login'}
response = requests.post(url, data=info)
print(response.text)
Ahmed Soliman
  • 1,662
  • 1
  • 11
  • 16
0

I think you need to send form-data instead of a json.

Maybe your question is related to this one

Samuel O.D.
  • 346
  • 2
  • 13