I'm trying to create a simple php login page, for testing purposes.
Basically, it just needs username, password and submit.
I have found this easy code and it works fine:
<?php
session_start(); $username = $password = $userError = $passError = '';
if(isset($_POST['sub'])){
$username = $_POST['username']; $password = $_POST['password'];
if($username === 'admin' && $password === 'password'){
$_SESSION['login'] = true; header('LOCATION:wherever.php'); die();
}
if($username !== 'admin' || $password !== 'pass') echo "Invalid";
else echo "Valid";
}
echo "<!DOCTYPE html>
<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>
<head>
<meta http-equiv='content-type' content='text/html;charset=utf-8' />
<title>Login</title>
<style type='text.css'>
@import common.css;
</style>
</head>
<body>
<form name='input' action='{$_SERVER['PHP_SELF']}' method='post'>
<label for='username'></label><input type='text' value='$username' id='username' name='username' />
<div class='error'>$userError</div>
<label for='password'></label><input type='password' value='$password' id='password' name='password' />
<div class='error'>$passError</div>
<input type='submit' value='Submit' name='sub' />
</form>
<script type='text/javascript' src='common.js'></script>
</body>
</html>";
?>
Now the purpose of this page should be this:
On submitting "admin", "pass" return "Valid". Anything else, return "Invalid".
If I click submit and login, Valid/Invalid appear accordingly on top.
The problem is that when I try to get the same output with curl (http post?), it fails to print any.
I have tried this, according to all the answers I could find it's correct:
curl --data "username=admin&password=pass&sub=Submit" http://altervista.mypagegoeshere.org/index.php -o /root/Desktop/out.txt
But it shows no output.
**Other answers suggested replacing --data
with -F
This action still prints neither "Valid" nor "Invalid", but does print the whole html code of the page.**
Curling just the address gived back all the html, so that's correct.
I need the curl input to return Valid
, or Invalid
.
What am I doing wrong?
According to the answers here on SO and to https://curl.haxx.se/docs/manual.html the curl command I wrote is correct.
I am running this from the ubuntu terminal, I don't know if that's helpful.